https://github.com/IvyXu420 created https://github.com/llvm/llvm-project/pull/230806
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. >From fb0ce51643420c0757bbcb9fc9bffbb667d216b5 Mon Sep 17 00:00:00 2001 From: Ivy Xu <[email protected]> Date: Sat, 10 Oct 2026 23:23:38 +0800 Subject: [PATCH] Handle non-template function in `Sema::resolveAddressOfSingleOverloadCandidate` properly --- clang/docs/ReleaseNotes.md | 3 +++ clang/lib/Sema/SemaOverload.cpp | 12 ++++++++++++ .../over/over.over/p2-resolve-single-template-id.cpp | 12 ++++++++++++ 3 files changed, 27 insertions(+) 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}} + } +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
