Skip to content

[clang] member pointer class qualification fix #142081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025

Conversation

mizvekov
Copy link
Contributor

This fixes a regression introduced in #130537,
which was reported here: #132401 (comment)

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 fixes a regression introduced in #130537

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.
@mizvekov mizvekov requested review from erichkeane and zyn0217 May 30, 2025 03:00
@mizvekov mizvekov self-assigned this May 30, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 30, 2025
@llvmbot
Copy link
Member

llvmbot commented May 30, 2025

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

Changes

This fixes a regression introduced in #130537,
which was reported here: #132401 (comment)

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.


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+1-1)
  • (modified) clang/test/SemaCXX/member-pointer.cpp (+22)
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 51bfca9da4231..5566057cccef8 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2127,7 +2127,7 @@ static TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch(
         TA = S.Context.getTypeDeclType(MPA->getMostRecentCXXRecordDecl());
       } else {
         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");
       return DeduceTemplateArgumentsByTypeMatch(
diff --git a/clang/test/SemaCXX/member-pointer.cpp b/clang/test/SemaCXX/member-pointer.cpp
index c94c26fbcbb28..6bb0686be7403 100644
--- a/clang/test/SemaCXX/member-pointer.cpp
+++ b/clang/test/SemaCXX/member-pointer.cpp
@@ -408,3 +408,25 @@ namespace deduction2 {
     void i() { e(&C::h); }
   };
 } // 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

@mizvekov mizvekov merged commit 3609e09 into main May 30, 2025
14 checks passed
@mizvekov mizvekov deleted the users/mizvekov/fix-type-qualifier-memberptr branch May 30, 2025 05:25
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
This fixes a regression introduced in
llvm#130537,
which was reported here:
llvm#132401 (comment)

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.
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