Skip to content

[clang] fix crash with ADL for member pointers with dependent class #132977

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

Conversation

mizvekov
Copy link
Contributor

Fix crash when looking up associated namespaces for member pointers with an unknown class, due to dependency.

It was a regression introduced in #131965 and reported here: #132317 (comment)

No change notes since the regression was never released.

Fix crash when looking up associated namespaces for member pointers with an
unknown class, due to dependency.

It was a regression introduced in #131965
and reported here: #132317 (comment)

No change notes since the regression was never released.
@mizvekov mizvekov self-assigned this Mar 25, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 25, 2025

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

Changes

Fix crash when looking up associated namespaces for member pointers with an unknown class, due to dependency.

It was a regression introduced in #131965 and reported here: #132317 (comment)

No change notes since the regression was never released.


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaLookup.cpp (+2-2)
  • (modified) clang/test/SemaCXX/member-pointer.cpp (+10)
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 59dc6df5fbe9f..876340010cf5f 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -3210,8 +3210,8 @@ addAssociatedClassesAndNamespaces(AssociatedLookup &Result, QualType Ty) {
     //        X.
     case Type::MemberPointer: {
       const MemberPointerType *MemberPtr = cast<MemberPointerType>(T);
-      addAssociatedClassesAndNamespaces(
-          Result, MemberPtr->getMostRecentCXXRecordDecl());
+      if (CXXRecordDecl *Class = MemberPtr->getMostRecentCXXRecordDecl())
+        addAssociatedClassesAndNamespaces(Result, Class);
       T = MemberPtr->getPointeeType().getTypePtr();
       continue;
     }
diff --git a/clang/test/SemaCXX/member-pointer.cpp b/clang/test/SemaCXX/member-pointer.cpp
index 3d9dd05755b8c..fa3e6a5a4bcf7 100644
--- a/clang/test/SemaCXX/member-pointer.cpp
+++ b/clang/test/SemaCXX/member-pointer.cpp
@@ -355,3 +355,13 @@ namespace GH132401 {
   };
   template struct CallableHelper<void (QIODevice::*)()>;
 } // namespace GH132401
+
+namespace adl_dependent_class {
+  struct A {
+    template <class T> A(T);
+  };
+  struct C;
+  template <class T> void d(void (T::*)());
+  void f(A);
+  void g() { f(d<C>); }
+} // namespace adl_dependent_class

@mizvekov
Copy link
Contributor Author

Since this fixes a regression recently introduced, which was picked up by upstream users,
I will land this as soon as pre-commit checks are done.

@mizvekov mizvekov merged commit 9606159 into main Mar 25, 2025
14 checks passed
@mizvekov mizvekov deleted the users/mizvekov/member-pointer-dependent-class-crash-adl branch March 25, 2025 21:15
Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change seems reasonable, thanks for 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