[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 5 07:57:01 PDT 2023


royjacobson created this revision.
royjacobson added reviewers: shafik, erichkeane.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I checked if the member function declaration was a copy constructor, but it's not sufficient; We need to check
the arguments against the instantiated class.

Fixed https://github.com/llvm/llvm-project/issues/62555


Repository:
  rG LLVM Github Monorepo

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
@@ -2523,9 +2523,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,
@@ -2548,8 +2545,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())
@@ -2752,6 +2747,15 @@
   if (IsExplicitSpecialization && !isFriend)
     SemaRef.CompleteMemberSpecialization(Method, Previous);
 
+  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.519857.patch
Type: text/x-patch
Size: 2950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230505/5933eb7a/attachment.bin>


More information about the cfe-commits mailing list