[clang] member pointer class qualification fix (#142081)

This fixes a regression introduced in
https://github.com/llvm/llvm-project/pull/130537,
which was reported here:
https://github.com/llvm/llvm-project/pull/132401#issuecomment-2839690599

When deducing member pointers class, ignore top level qualifiers on the
argument side, since the class portion of a member pointer is a
nested-name-specifier, and these just nominate an entity.

Qualifiers on the parameter side are fine since deduction allows the
parameter side to be more qualified, and these qualifiers won't be part
of the result.

Since this regression was never released, there are no release notes.
This commit is contained in:
Matheus Izvekov 2025-05-30 02:25:21 -03:00 committed by GitHub
parent 6cb087a725
commit 3609e09aa7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -2127,7 +2127,7 @@ static TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch(
TA = S.Context.getTypeDeclType(MPA->getMostRecentCXXRecordDecl()); TA = S.Context.getTypeDeclType(MPA->getMostRecentCXXRecordDecl());
} else { } else {
NestedNameSpecifier *QA = MPA->getQualifier(); NestedNameSpecifier *QA = MPA->getQualifier();
TA = QualType(QA->translateToType(S.Context), 0); TA = QualType(QA->translateToType(S.Context), 0).getUnqualifiedType();
} }
assert(!TA.isNull() && "member pointer with non-type class"); assert(!TA.isNull() && "member pointer with non-type class");
return DeduceTemplateArgumentsByTypeMatch( return DeduceTemplateArgumentsByTypeMatch(

View File

@ -408,3 +408,25 @@ namespace deduction2 {
void i() { e(&C::h); } void i() { e(&C::h); }
}; };
} // namespace deduction2 } // namespace deduction2
namespace deduction_qualifiers {
struct A {
int v;
};
using CA = const A;
template <class T> void g(const T&, int T::*);
template <class T> void h(const T&, int CA::*);
void test(const A a, A b) {
g(a, &A::v);
g(a, &CA::v);
h(a, &A::v);
h(a, &CA::v);
g(b, &A::v);
g(b, &CA::v);
h(b, &A::v);
h(b, &CA::v);
}
} // namespace deduction_qualifiers