[PATCH] D139038: [Clang] Don't consider default constructors ineligible if the more constrained constructor is a template
Roy Jacobson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 5 13:02:47 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7d58c95635cc: [Clang] Don't consider default constructors ineligible if the more constrained… (authored by royjacobson).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139038/new/
https://reviews.llvm.org/D139038
Files:
clang/lib/AST/DeclCXX.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/constrained-special-member-functions.cpp
Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===================================================================
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -225,3 +225,43 @@
S<2, 2> s2;
}
}
+
+namespace GH59206 {
+
+struct A {
+ A() = default; //eligible, second constructor unsatisfied
+ template<class... Args>
+ A(Args&&... args) requires (sizeof...(Args) > 0) {}
+};
+
+struct B {
+ B() = default; //ineligible, second constructor more constrained
+ template<class... Args>
+ B(Args&&... args) requires (sizeof...(Args) == 0) {}
+};
+
+struct C {
+ C() = default; //eligible, but
+ template<class... Args> //also eligible and non-trivial
+ C(Args&&... args) {}
+};
+
+struct D : B {};
+
+static_assert(__is_trivially_copyable(A), "");
+static_assert(__is_trivially_copyable(B), "");
+static_assert(__is_trivially_copyable(C), "");
+static_assert(__is_trivially_copyable(D), "");
+
+// FIXME: Update when https://github.com/llvm/llvm-project/issues/59206 is
+// resolved.
+static_assert(!__is_trivial(A), "");
+static_assert(!__is_trivial(B), "");
+static_assert(!__is_trivial(C), "");
+static_assert(__is_trivial(D), "");
+static_assert(__is_trivially_constructible(A), "");
+static_assert(__is_trivially_constructible(B), "");
+static_assert(__is_trivially_constructible(C), "");
+static_assert(__is_trivially_constructible(D), "");
+
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -18193,8 +18193,11 @@
CXXMethodDecl *M1,
CXXMethodDecl *M2,
Sema::CXXSpecialMember CSM) {
+ // We don't want to compare templates to non-templates: See
+ // https://github.com/llvm/llvm-project/issues/59206
if (CSM == Sema::CXXDefaultConstructor)
- return true;
+ return bool(M1->getDescribedFunctionTemplate()) ==
+ bool(M2->getDescribedFunctionTemplate());
if (!Context.hasSameType(M1->getParamDecl(0)->getType(),
M2->getParamDecl(0)->getType()))
return false;
Index: clang/lib/AST/DeclCXX.cpp
===================================================================
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -1378,7 +1378,11 @@
}
void CXXRecordDecl::addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD,
- unsigned SMKind) {
+ unsigned SMKind) {
+ // FIXME: We shouldn't change DeclaredNonTrivialSpecialMembers if `MD` is
+ // a function template, but this needs CWG attention before we break ABI.
+ // See https://github.com/llvm/llvm-project/issues/59206
+
if (const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
if (DD->isUserProvided())
data().HasIrrelevantDestructor = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139038.480215.patch
Type: text/x-patch
Size: 3063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221205/16c181bc/attachment.bin>
More information about the cfe-commits
mailing list