[clang] 25f76c9 - [clang] Find conversion function templates for in-class specializations (#218316)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 31 05:16:28 PDT 2026
Author: Kunal Dubey
Date: 2026-08-31T14:16:22+02:00
New Revision: 25f76c98fe049a506396d8c1709cc0efc7d01202
URL: https://github.com/llvm/llvm-project/commit/25f76c98fe049a506396d8c1709cc0efc7d01202
DIFF: https://github.com/llvm/llvm-project/commit/25f76c98fe049a506396d8c1709cc0efc7d01202.diff
LOG: [clang] Find conversion function templates for in-class specializations (#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
Added:
Modified:
clang/docs/ReleaseNotes.md
clang/lib/Sema/SemaLookup.cpp
clang/test/SemaCXX/conversion-function.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 512b1d1d3be01..32ee602dc8472 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -551,6 +551,11 @@ features cannot lower the translation-unit ABI level;
parameter that follows a parameter pack (e.g.
`template <typename... T> S::S(T..., int = 10) {}`). (#GH216211)
+- 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()`.
+ (#GH218261)
+
- Fixed an assertion when an ill-formed qualified member function definition
inside a union caused the union to be treated as a polymorphic class.
(#GH213854)
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 43419c46dd2bf..319c228bad3b0 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 {
More information about the cfe-commits
mailing list