[PATCH] D138603: [Clang] Implement LWG3823 for __is_aggregate

Roy Jacobson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 23 13:23:01 PST 2022


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

LWG3823 says that arrays of incomplete types are aggregates. Fix the clang builtin to match that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138603

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===================================================================
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@
           Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
     return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+    if (ArgTy->isArrayType() || ArgTy->isVoidType())
+      return true;
+
+    return !S.RequireCompleteType(
+        Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
+
   // C++1z [meta.unary.prop]:
   //   remove_all_extents_t<T> shall be a complete type or cv void.
-  case UTT_IsAggregate:
   case UTT_IsTrivial:
   case UTT_IsTriviallyCopyable:
   case UTT_IsStandardLayout:
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -304,6 +304,8 @@
 - GNU attributes being applied prior to standard attributes would be handled
   improperly, which was corrected to match the behaviour exhibited by GCC.
   `Issue 58229 <https://github.com/llvm/llvm-project/issues/58229>`_
+- The builtin type trait ``__is_aggregate`` now returns ``true`` for arrays of incomplete
+  types in accordance with the suggested fix for `LWG3823 https://cplusplus.github.io/LWG/issue3823`_
 
 Improvements to Clang's diagnostics
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138603.477588.patch
Type: text/x-patch
Size: 2747 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221123/3e67d12a/attachment-0001.bin>


More information about the cfe-commits mailing list