[PATCH] D143891: [Clang] Adjust triviality computation in QualType::isTrivialType to C++20 cases.

Roy Jacobson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 22 13:27:32 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG000ec50ef511: [Clang] Adjust triviality computation in QualType::isTrivialType to C++20 cases. (authored by royjacobson).

Changed prior to commit:
  https://reviews.llvm.org/D143891?vs=496884&id=499635#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143891/new/

https://reviews.llvm.org/D143891

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Type.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
@@ -265,3 +265,37 @@
 static_assert(__is_trivially_constructible(D), "");
 
 }
+
+namespace GH60697 {
+
+template <class T>
+struct X {
+    X() requires false = default;
+};
+static_assert(!__is_trivial(X<int>));
+
+template <class T>
+struct S {
+    S() requires(__is_trivially_constructible(T)) = default;
+
+    S() requires(!__is_trivially_constructible(T) &&
+                  __is_constructible(T)) {}
+
+    T t;
+};
+
+struct D {
+    D(int i) : i(i) {}
+    int i;
+};
+static_assert(!__is_trivially_constructible(D));
+static_assert(!__is_constructible(D));
+static_assert(!__is_trivial(D));
+
+static_assert(!__is_trivially_constructible(S<D>));
+static_assert(!__is_constructible(S<D>));
+
+static_assert(__is_trivial(S<int>));
+static_assert(!__is_trivial(S<D>));
+
+}
Index: clang/lib/AST/Type.cpp
===================================================================
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2501,11 +2501,13 @@
     return true;
   if (const auto *RT = CanonicalType->getAs<RecordType>()) {
     if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
-      // C++11 [class]p6:
-      //   A trivial class is a class that has a default constructor,
-      //   has no non-trivial default constructors, and is trivially
-      //   copyable.
-      return ClassDecl->hasDefaultConstructor() &&
+      // C++20 [class]p6:
+      //   A trivial class is a class that is trivially copyable, and
+      //     has one or more eligible default constructors such that each is
+      //     trivial.
+      // FIXME: We should merge this definition of triviality into
+      // CXXRecordDecl::isTrivial. Currently it computes the wrong thing.
+      return ClassDecl->hasTrivialDefaultConstructor() &&
              !ClassDecl->hasNonTrivialDefaultConstructor() &&
              ClassDecl->isTriviallyCopyable();
     }
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -58,6 +58,8 @@
 
 ABI Changes in This Version
 ---------------------------
+- ``__is_trivial`` has changed for a small category of classes with constrained default constructors (`#60697 <https://github.com/llvm/llvm-project/issues/60697>`_).
+  *FIXME: Remove this note if we've backported this change to the Clang 16 branch.*
 
 What's New in Clang |release|?
 ==============================


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143891.499635.patch
Type: text/x-patch
Size: 2703 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230222/6a6325d7/attachment-0001.bin>


More information about the cfe-commits mailing list