[clang] [clang] Fix unresolved overloaded conversion function reference (PR #230806)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 10 08:36:28 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Ivy Xu (IvyXu420)
<details>
<summary>Changes</summary>
According to [C++ [over.over]p5](https://eel.is/c++draft/over.over#<!-- -->5):
> [...] If more than one function in the set remains, all function
> template specializations in the set are eliminated if the set also
> contains a function that is not a function template specialization. [...]
However, in `Sema::resolveAddressOfSingleOverloadCandidate`, this part was missed, causing `IsResultAmbiguous`
to be set to true and an error to be emitted wrongly.
Fixes #<!-- -->230682.
AI was used to help understand the code.
---
Full diff: https://github.com/llvm/llvm-project/pull/230806.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.md (+3)
- (modified) clang/lib/Sema/SemaOverload.cpp (+12)
- (modified) clang/test/CXX/over/over.over/p2-resolve-single-template-id.cpp (+12)
``````````diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 77a1e73bc8af6..d676983e42ce5 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -931,6 +931,9 @@ features cannot lower the translation-unit ABI level;
constrained placeholder type (such as `C auto`) whose default argument
contains a lambda. (#GH230539)
+- Fixed a bug where Clang failed to resolve a reference to an overloaded
+ conversion function when one of the overloads was non-template. (#GH230682)
+
#### Bug Fixes to AST Handling
- Fixed a non-deterministic ordering of unused local typedefs that made
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 62b6ad8ffb564..2ca12f7a172e7 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -14375,6 +14375,18 @@ Sema::resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &Pair) {
// FD has the same CUDA preference than Result. Continue to check
// constraints.
+ // C++ [over.over]p5:
+ // [...] If more than one function in the set remains, all function
+ // template specializations in the set are eliminated if the set also
+ // contains a function that is not a function template specialization.
+ // [...]
+ if (Result->isFunctionTemplateSpecialization() !=
+ FD->isFunctionTemplateSpecialization()) {
+ if (!FD->isFunctionTemplateSpecialization())
+ FoundBetter();
+ continue;
+ }
+
// C++ [over.over]p5:
// [...] Any given non-template function F0 is eliminated if the set
// contains a second non-template function that is more
diff --git a/clang/test/CXX/over/over.over/p2-resolve-single-template-id.cpp b/clang/test/CXX/over/over.over/p2-resolve-single-template-id.cpp
index e538b99a1eb0b..260bbd5a8c185 100644
--- a/clang/test/CXX/over/over.over/p2-resolve-single-template-id.cpp
+++ b/clang/test/CXX/over/over.over/p2-resolve-single-template-id.cpp
@@ -189,3 +189,15 @@ namespace member_pointers {
{ bool b = &s.h<int>; } // expected-error {{cannot form member pointer of type 'bool' without '&' and class name}}
}
}
+
+namespace conversion_functions {
+ struct S {
+ operator int();
+
+ template<typename T> operator T();
+};
+
+ void test() {
+ &S::operator int; // expected-warning {{expression result unused}}
+ }
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/230806
More information about the cfe-commits
mailing list