https://github.com/xakep8 created 
https://github.com/llvm/llvm-project/pull/218316

Allow redeclaration lookup to consider conversion function templates allowing 
Clang to match an in-class specialization such as `template<> operator int()` 
against a prior conversion function template `template<class T> operator T()`.

Fixes #218261 

>From ee3edd0e3b76341577a2058d86c4322ff0e6c156 Mon Sep 17 00:00:00 2001
From: Kunal Dubey <[email protected]>
Date: Mon, 24 Aug 2026 10:02:05 +0530
Subject: [PATCH] [clang] Find conversion function templates for in-class
 specializations

Allow redeclaration lookup to consider conversion function templates allowing 
Clang to match an in-class specialization such as `template<> operator int()` 
against a prior conversion function template `template<class T> operator T()`.
---
 clang/lib/Sema/SemaLookup.cpp              |  2 +-
 clang/test/SemaCXX/conversion-function.cpp | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 43129800e9813..b385392150d6c 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1158,7 +1158,7 @@ static bool LookupDirect(Sema &S, LookupResult &R, const 
DeclContext *DC) {
   //   name lookup. Instead, any conversion function templates visible in the
   //   context of the use are considered. [...]
   const CXXRecordDecl *Record = cast<CXXRecordDecl>(DC);
-  if (!Record->isCompleteDefinition())
+  if (!Record->isCompleteDefinition() && !R.isForRedeclaration())
     return Found;
 
   // For conversion operators, 'operator auto' should only match
diff --git a/clang/test/SemaCXX/conversion-function.cpp 
b/clang/test/SemaCXX/conversion-function.cpp
index 717c73c4786eb..e00553fbb20a3 100644
--- a/clang/test/SemaCXX/conversion-function.cpp
+++ b/clang/test/SemaCXX/conversion-function.cpp
@@ -473,6 +473,24 @@ struct S {
 };
 }
 
+#if __cplusplus >= 201103L
+namespace GH218261 {
+  struct S {
+    template <typename T>
+    constexpr operator T() const {
+      return 10;
+    }
+
+    template <>
+    constexpr operator int() const {
+      return 4;
+    }
+  };
+
+  static_assert(S().operator int() == 4, "");
+}
+#endif
+
 #if __cplusplus >= 201103L
 namespace dependent_conversion_function_id_lookup {
 namespace gh77583 {

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to