Skip to content

[Clang] Fix a regression introduced by #140073 #140288

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 16, 2025

Conversation

cor3ntin
Copy link
Contributor

Pointer to data member don't decay, assuming they do caused an assertion failure.

Pointer to data member don't decay, assuming they do caused
an assertion failure.
@cor3ntin cor3ntin requested a review from alexfh May 16, 2025 17:54
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 16, 2025
@llvmbot
Copy link
Member

llvmbot commented May 16, 2025

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

Changes

Pointer to data member don't decay, assuming they do caused an assertion failure.


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

2 Files Affected:

  • (modified) clang/include/clang/Sema/Overload.h (+2-1)
  • (modified) clang/test/SemaCXX/overload-resolution-deferred-templates.cpp (+23)
diff --git a/clang/include/clang/Sema/Overload.h b/clang/include/clang/Sema/Overload.h
index e88f764a0a601..a70335bef9dd4 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -435,7 +435,8 @@ class Sema;
 
           // A function pointer type can be resolved to a member function type,
           // which is still an identity conversion.
-          if (auto *N = T->getAs<MemberPointerType>())
+          if (auto *N = T->getAs<MemberPointerType>();
+              N && N->isMemberFunctionPointer())
             T = C.getDecayedType(N->getPointeeType());
           return T;
         };
diff --git a/clang/test/SemaCXX/overload-resolution-deferred-templates.cpp b/clang/test/SemaCXX/overload-resolution-deferred-templates.cpp
index d559fb23ca043..4c5ac5dcbbd04 100644
--- a/clang/test/SemaCXX/overload-resolution-deferred-templates.cpp
+++ b/clang/test/SemaCXX/overload-resolution-deferred-templates.cpp
@@ -251,3 +251,26 @@ void f() {
   e.g(&N::f);
 }
 }
+
+#if __cplusplus >= 201402
+namespace PointerToMemData {
+struct N {
+  int field;
+};
+template <typename It, typename T>
+struct B {
+  B(It, T);
+  template <typename It2>
+  B(B<It2, T>);
+};
+template <typename T>
+struct C {
+  auto g() { return B<int, T>(0, T{}); }
+};
+void f() {
+  using T = decltype(C<decltype(&N::field)>{}.g());
+}
+
+}
+
+#endif

@cor3ntin
Copy link
Contributor Author

Landing to fix a regression, feel free to do post-commit reviews

@cor3ntin cor3ntin merged commit efa2833 into llvm:main May 16, 2025
14 checks passed
@alexfh
Copy link
Contributor

alexfh commented May 19, 2025

This helps with the crashes we've seen so far. Thanks!

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