[PATCH] D149961: [Sema] Mark ineligibility of special member functions correctly
Roy Jacobson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 19 07:29:30 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f59bee3d58f: [Sema] Mark ineligibility of special member functions correctly (authored by royjacobson).
Changed prior to commit:
https://reviews.llvm.org/D149961?vs=519857&id=523765#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149961/new/
https://reviews.llvm.org/D149961
Files:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateInstantiateDecl.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
@@ -299,3 +299,16 @@
static_assert(!__is_trivial(S<D>));
}
+
+namespace GH62555 {
+
+template <bool B>
+struct ExplicitTemplateArgs {
+ ExplicitTemplateArgs(ExplicitTemplateArgs&&) = default;
+ ExplicitTemplateArgs(ExplicitTemplateArgs<false>&&) requires B {};
+};
+
+static_assert(__is_trivially_copyable(ExplicitTemplateArgs<false>));
+static_assert(__is_trivially_copyable(ExplicitTemplateArgs<true>));
+
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2524,9 +2524,6 @@
Constructor->getConstexprKind(), InheritedConstructor(),
TrailingRequiresClause);
Method->setRangeEnd(Constructor->getEndLoc());
- if (Constructor->isDefaultConstructor() ||
- Constructor->isCopyOrMoveConstructor())
- Method->setIneligibleOrNotSelected(true);
} else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) {
Method = CXXDestructorDecl::Create(
SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo,
@@ -2549,8 +2546,6 @@
SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo, SC,
D->UsesFPIntrin(), D->isInlineSpecified(), D->getConstexprKind(),
D->getEndLoc(), TrailingRequiresClause);
- if (D->isMoveAssignmentOperator() || D->isCopyAssignmentOperator())
- Method->setIneligibleOrNotSelected(true);
}
if (D->isInlined())
@@ -2753,6 +2748,22 @@
if (IsExplicitSpecialization && !isFriend)
SemaRef.CompleteMemberSpecialization(Method, Previous);
+ // If the method is a special member function, we need to mark it as
+ // ineligible so that Owner->addDecl() won't mark the class as non trivial.
+ // At the end of the class instantiation, we calculate eligibility again and
+ // then we adjust trivility if needed.
+ // We need this check to happen only after the method parameters are set,
+ // because being e.g. a copy constructor depends on the instantiated
+ // arguments.
+ if (auto *Constructor = dyn_cast<CXXConstructorDecl>(Method)) {
+ if (Constructor->isDefaultConstructor() ||
+ Constructor->isCopyOrMoveConstructor())
+ Method->setIneligibleOrNotSelected(true);
+ } else if (Method->isCopyAssignmentOperator() ||
+ Method->isMoveAssignmentOperator()) {
+ Method->setIneligibleOrNotSelected(true);
+ }
+
// If there's a function template, let our caller handle it.
if (FunctionTemplate) {
// do nothing
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -58,7 +58,8 @@
ABI Changes in This Version
---------------------------
-
+- A bug in evaluating the ineligibility of some special member functions has been fixed. This can
+ make some classes trivially copyable that were not trivially copyable before. (`#62555 <https://github.com/llvm/llvm-project/issues/62555>`_)
What's New in Clang |release|?
==============================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149961.523765.patch
Type: text/x-patch
Size: 3389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230519/15eaf07b/attachment.bin>
More information about the cfe-commits
mailing list