1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 2 3 static_assert(__is_literal(int), "fail"); 4 static_assert(__is_literal_type(int), "fail"); // alternate spelling for GCC 5 static_assert(__is_literal(void*), "fail"); 6 enum E { E1 }; 7 static_assert(__is_literal(E), "fail"); 8 static_assert(__is_literal(decltype(E1)), "fail"); 9 typedef int IAR[10]; 10 static_assert(__is_literal(IAR), "fail"); 11 typedef int Vector __attribute__((vector_size(16))); 12 typedef int VectorExt __attribute__((ext_vector_type(4))); 13 static_assert(__is_literal(Vector), "fail"); 14 static_assert(__is_literal(VectorExt), "fail"); 15 16 // C++0x [basic.types]p10: 17 // A type is a literal type if it is: 18 // [...] 19 // -- a class type that has all of the following properties: 20 // -- it has a trivial destructor 21 // -- every constructor call and full-expression in the 22 // brace-or-equal-initializers for non-static data members (if an) is 23 // a constant expression, 24 // -- it is an aggregate type or has at least one constexpr constructor 25 // or constructor template that is not a copy or move constructor, and 26 // -- it has all non-static data members and base classes of literal 27 // types 28 struct Empty {}; 29 struct LiteralType { 30 int x; 31 E e; 32 IAR arr; 33 Empty empty; 34 int method(); 35 }; 36 struct HasDtor { ~HasDtor(); }; 37 38 class NonAggregate { int x; }; 39 struct HasNonLiteralBase : NonAggregate {}; 40 struct HasNonLiteralMember { HasDtor x; }; 41 42 static_assert(__is_literal(Empty), "fail"); 43 static_assert(__is_literal(LiteralType), "fail"); 44 static_assert(!__is_literal(HasDtor), "fail"); 45 static_assert(!__is_literal(NonAggregate), "fail"); 46 static_assert(!__is_literal(HasNonLiteralBase), "fail"); 47 static_assert(!__is_literal(HasNonLiteralMember), "fail"); 48 49 // FIXME: Test constexpr constructors and non-static members with initializers 50 // when Clang supports them: 51 #if 0 52 extern int f(); 53 struct HasNonConstExprMemInit { 54 int x = f(); 55 constexpr HasNonConstExprMemInit(int y) {} 56 }; 57 static_assert(!__is_literal(HasNonConstExprMemInit), "fail"); 58 59 class HasConstExprCtor { 60 int x; 61 public: 62 constexpr HasConstExprCtor(int x) : x(x) {} 63 }; 64 template <typename T> class HasConstExprCtorTemplate { 65 T x; 66 public: 67 template <typename U> constexpr HasConstExprCtorTemplate(U y) : x(y) {} 68 }; 69 static_assert(__is_literal(HasConstExprCtor), "fail"); 70 static_assert(__is_literal(HasConstExprCtorTemplate), "fail"); 71 #endif 72