Skip to content

Conversation

@cor3ntin
Copy link
Contributor

@cor3ntin cor3ntin commented Jul 28, 2025

Static functions have an implicit object argument during deduction.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 28, 2025

@llvm/pr-subscribers-clang

Author: Corentin Jabot (cor3ntin)

Changes

We should not skip the first argument of static member functions when initalizing a conversion sequence for a non-deducible parameter.


Full diff: https://github.com/llvm/llvm-project/pull/150893.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaOverload.cpp (+3-3)
  • (modified) clang/test/SemaCXX/cxx2b-deducing-this.cpp (+32)
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 5dd5b495480d9..5134e77ecf695 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -13093,9 +13093,9 @@ CompleteNonViableCandidate(Sema &S, OverloadCandidate *Cand,
   } else if (Cand->Function) {
     ParamTypes =
         Cand->Function->getType()->castAs<FunctionProtoType>()->getParamTypes();
-    if (isa<CXXMethodDecl>(Cand->Function) &&
-        !isa<CXXConstructorDecl>(Cand->Function) && !Reversed &&
-        !Cand->Function->hasCXXExplicitFunctionObjectParameter()) {
+    if (auto *M = dyn_cast<CXXMethodDecl>(Cand->Function);
+        M && !isa<CXXConstructorDecl>(M) && !Reversed &&
+        M->isImplicitObjectMemberFunction()) {
       // Conversion 0 is 'this', which doesn't have a corresponding parameter.
       ConvIdx = 1;
       if (CSK == OverloadCandidateSet::CSK_Operator &&
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 2253cbb26285e..fcbe0f62e6d4f 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -1357,3 +1357,35 @@ void Bar(this int) { // expected-note {{candidate function}}
 }
 
 }
+
+namespace GH147046_regression {
+
+template <typename z> struct ai {
+    ai(z::ah);
+};
+
+template <typename z> struct ak {
+    template <typename am> void an(am, z);
+    template <typename am> static void an(am, ai<z>);
+};
+template <typename> struct ao {};
+
+template <typename ap>
+auto ar(ao<ap> at) -> decltype(ak<ap>::an(at, 0));
+// expected-note@-1 {{candidate template ignored: substitution failure [with ap = GH147046_regression::ay]: no matching function for call to 'an'}}
+
+class aw;
+struct ax {
+    typedef int ah;
+};
+struct ay {
+    typedef aw ah;
+};
+
+ao<ay> az ;
+ai<ax> bd(0);
+void f() {
+    ar(az); // expected-error {{no matching function for call to 'ar'}}
+}
+
+}

Static functions have an implicit object argument during deduction,
@cor3ntin cor3ntin force-pushed the corentin/GH147046_regression branch from a8fb90c to 8af7ce0 Compare July 28, 2025 08:10
@cor3ntin cor3ntin merged commit d803c61 into llvm:main Jul 28, 2025
9 checks passed
@HighCommander4
Copy link
Collaborator

@cor3ntin the regression being fixed here snuck into the 21 release -- do you think we could backport the fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants