diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 5dd5b495480d9..76e189d536849 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -8042,8 +8042,8 @@ static void AddTemplateOverloadCandidateImmediately( Candidate.IgnoreObjectArgument = isa(Candidate.Function) && - cast(Candidate.Function) - ->isImplicitObjectMemberFunction() && + !cast(Candidate.Function) + ->isExplicitObjectMemberFunction() && !isa(Candidate.Function); Candidate.ExplicitCallArguments = Args.size(); 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 struct ai { + ai(z::ah); +}; + +template struct ak { + template void an(am, z); + template static void an(am, ai); +}; +template struct ao {}; + +template +auto ar(ao at) -> decltype(ak::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 az ; +ai bd(0); +void f() { + ar(az); // expected-error {{no matching function for call to 'ar'}} +} + +}