-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Clang] Fix an assertion in the resolution of perfect matches #140073
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
Conversation
Function pointers can have an identity conversion to a pointer to member function if they are resolved to a member function. Fix a regression introduced by llvm#136203
@llvm/pr-subscribers-clang Author: cor3ntin (cor3ntin) ChangesFunction pointers can have an identity conversion to a pointer to member function if they are resolved to a member function. Fix a regression introduced by #136203 Full diff: https://github.com/llvm/llvm-project/pull/140073.diff 2 Files Affected:
diff --git a/clang/include/clang/Sema/Overload.h b/clang/include/clang/Sema/Overload.h
index 58452e159821a..f980c9d4a85df 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -430,8 +430,14 @@ class Sema;
if (!ReferenceBinding) {
#ifndef NDEBUG
auto Decay = [&](QualType T) {
- return (T->isArrayType() || T->isFunctionType()) ? C.getDecayedType(T)
- : T;
+ T = (T->isArrayType() || T->isFunctionType()) ? C.getDecayedType(T)
+ : T;
+
+ // A function pointer type can be resolved to a member function type,
+ // which is still an identity conversion.
+ if (auto *N = T->getAs<MemberPointerType>())
+ T = C.getDecayedType(N->getPointeeType());
+ return T;
};
// The types might differ if there is an array-to-pointer conversion
// an function-to-pointer conversion, or lvalue-to-rvalue conversion.
diff --git a/clang/test/SemaCXX/overload-resolution-deferred-templates.cpp b/clang/test/SemaCXX/overload-resolution-deferred-templates.cpp
index 277c5df3bb62b..d559fb23ca043 100644
--- a/clang/test/SemaCXX/overload-resolution-deferred-templates.cpp
+++ b/clang/test/SemaCXX/overload-resolution-deferred-templates.cpp
@@ -232,3 +232,22 @@ struct InitListAreNotPerfectCpy {
};
InitListAreNotPerfectCpy InitListAreNotPerfectCpy_test({InitListAreNotPerfectCpy{}});
+
+namespace PointerToMemFunc {
+template <typename>
+class A;
+struct N {
+ template <typename T>
+ void f(T);
+};
+template <typename T>
+struct E {
+ template <class = A<int>>
+ void g() = delete;
+ void g(void (T::*)(char));
+};
+void f() {
+ E<N> e;
+ e.g(&N::f);
+}
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the prompt fix! Looks good with one suggestion.
clang/include/clang/Sema/Overload.h
Outdated
@@ -430,8 +430,14 @@ class Sema; | |||
if (!ReferenceBinding) { | |||
#ifndef NDEBUG | |||
auto Decay = [&](QualType T) { | |||
return (T->isArrayType() || T->isFunctionType()) ? C.getDecayedType(T) | |||
: T; | |||
T = (T->isArrayType() || T->isFunctionType()) ? C.getDecayedType(T) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's not a single expression any more, a simple if
would be a bit nicer here, IMO.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/11663 Here is the relevant piece of the build log for the reference
|
@cor3ntin unfortunately, this fix causes assertion failures elsewhere:
The test is being reduced. |
@cor3ntin the reduced test case for the assertion failure above is: https://gcc.godbolt.org/z/zveexjqW3
|
Hi @cor3ntin, Would you please revert this change while resolving this failure case? I've attached a reproducer for this assert scenario to help with debugging. |
@Caslyn Expect a fix shortly. Thanks for the repro |
@alexfh Thanks a lot. I have a fix, a PR will be made once I run the tests |
Pointer to data member don't decay, assuming they do caused an assertion failure.
Function pointers can have an identity conversion to a pointer to member function if they are resolved to a member function.
Fix a regression introduced by #136203