[clang] [clang] Find conversion function templates for in-class specializations (PR #218316)
Kunal Dubey via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 24 06:47:26 PDT 2026
https://github.com/xakep8 updated https://github.com/llvm/llvm-project/pull/218316
>From ee3edd0e3b76341577a2058d86c4322ff0e6c156 Mon Sep 17 00:00:00 2001
From: Kunal Dubey <xakep8 at protonmail.com>
Date: Mon, 24 Aug 2026 10:02:05 +0530
Subject: [PATCH 1/3] [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 {
>From 40d423236cbd2dfaf94252b3dc3dbe88345cbb31 Mon Sep 17 00:00:00 2001
From: Kunal Dubey <xakep8 at protonmail.com>
Date: Mon, 24 Aug 2026 15:19:16 +0530
Subject: [PATCH 2/3] [clang] Added changes to Release Notes
---
clang/docs/ReleaseNotes.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 8c9467ca7b742..4673be3757065 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -528,6 +528,8 @@ 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()`.
+
#### Bug Fixes to AST Handling
- Fixed a non-deterministic ordering of unused local typedefs that made
>From 997fbb119c7a525c33be1afbbe838486fd3c8c9e Mon Sep 17 00:00:00 2001
From: Kunal Dubey <xakep8 at protonmail.com>
Date: Mon, 24 Aug 2026 19:17:16 +0530
Subject: [PATCH 3/3] [clang] updated release notes
Co-authored-by: Corentin Jabot <corentinjabot at gmail.com>
---
clang/docs/ReleaseNotes.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 4673be3757065..0476b1f51cbf3 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -528,7 +528,7 @@ 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()`.
+- 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)
#### Bug Fixes to AST Handling
More information about the cfe-commits
mailing list