[clang] 13c3228 - [Clang] Implement LWG3823 for __is_aggregate

Roy Jacobson via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 29 04:57:53 PST 2022


Author: Roy Jacobson
Date: 2022-11-29T14:57:47+02:00
New Revision: 13c32288354b6175527f4fdece623157d3637da3

URL: https://github.com/llvm/llvm-project/commit/13c32288354b6175527f4fdece623157d3637da3
DIFF: https://github.com/llvm/llvm-project/commit/13c32288354b6175527f4fdece623157d3637da3.diff

LOG: [Clang] Implement LWG3823 for __is_aggregate

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

Closes https://github.com/llvm/llvm-project/issues/59002

Reviewed By: cjdb

Differential Revision: https://reviews.llvm.org/D138603

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ffce71f8c38a..551070b27b2d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -304,6 +304,8 @@ Bug Fixes
 - 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
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 8b3cd4211f88..0980f507426c 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT,
           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:

diff  --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp
index 4369ed0c4672..76a67252c941 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@ void is_aggregate()
   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), "");


        


More information about the cfe-commits mailing list