[PATCH] D31637: [Sema] Implement LWG 2015 for the builtin type-traits.

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 3 18:35:34 PDT 2017


EricWF created this revision.

This patch implements LWG 2015 <http://cplusplus.github.io/LWG/lwg-defects.html#2015>, which requires than arrays used with [meta.unary.prop] traits have a complete element type.

If I'm not mistaken the correct thing to do is to retroactively apply it to C++11 even though it first appeared in the C++14 standard.


https://reviews.llvm.org/D31637

Files:
  lib/Sema/SemaExprCXX.cpp
  test/SemaCXX/type-traits-incomplete.cpp


Index: test/SemaCXX/type-traits-incomplete.cpp
===================================================================
--- test/SemaCXX/type-traits-incomplete.cpp
+++ test/SemaCXX/type-traits-incomplete.cpp
@@ -1,8 +1,15 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
 
-struct S; // expected-note 2 {{forward declaration of 'S'}}
+struct S; // expected-note 4 {{forward declaration of 'S'}}
+typedef S SAr[10];
+typedef S SArNB[];
+typedef S SArMB[10][2];
 
 void f() {
   __is_pod(S); // expected-error{{incomplete type 'S' used in type trait expression}}
   __is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait expression}}
+  __is_pod(S[10][2]); // expected-error{{incomplete type 'S' used in type trait expression}}
+  __is_pod(S[][10]); // expected-error{{incomplete type 'S' used in type trait expression}}
+  (void)__is_pod(void); // OK
+  (void)__is_pod(const volatile void); // OK
 }
Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -4081,10 +4081,11 @@
   case UTT_HasTrivialCopy:
   case UTT_HasTrivialDestructor:
   case UTT_HasVirtualDestructor:
-    // Arrays of unknown bound are expressly allowed.
-    QualType ElTy = ArgTy;
-    if (ArgTy->isIncompleteArrayType())
-      ElTy = S.Context.getAsArrayType(ArgTy)->getElementType();
+    // C++14 [meta.unary.prop]
+    //   remove_all_extents_t<T> shall be a complete type or
+    //   (possibly cv-qualified) void.
+    // See LWG 2015
+    QualType ElTy = S.Context.getBaseElementType(ArgTy);
 
     // The void type is expressly allowed.
     if (ElTy->isVoidType())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31637.93981.patch
Type: text/x-patch
Size: 1667 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170404/39a7e404/attachment.bin>


More information about the cfe-commits mailing list