1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2
3static_assert(__is_literal(int), "fail");
4static_assert(__is_literal_type(int), "fail"); // alternate spelling for GCC
5static_assert(__is_literal(void*), "fail");
6enum E { E1 };
7static_assert(__is_literal(E), "fail");
8static_assert(__is_literal(decltype(E1)), "fail");
9typedef int IAR[10];
10static_assert(__is_literal(IAR), "fail");
11typedef int Vector __attribute__((vector_size(16)));
12typedef int VectorExt __attribute__((ext_vector_type(4)));
13static_assert(__is_literal(Vector), "fail");
14static_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//           [DR1452 adds class types with trivial default constructors to
27//            this list]
28//        -- it has all non-static data members and base classes of literal
29//           types
30struct Empty {};
31struct LiteralType {
32  int x;
33  E e;
34  IAR arr;
35  Empty empty;
36  int method();
37};
38struct HasDtor { ~HasDtor(); };
39
40class NonAggregate { int x; };
41struct NonLiteral { NonLiteral(); };
42struct HasNonLiteralBase : NonLiteral {};
43struct HasNonLiteralMember { HasDtor x; };
44
45static_assert(__is_literal(Empty), "fail");
46static_assert(__is_literal(LiteralType), "fail");
47static_assert(__is_literal(NonAggregate), "fail");
48static_assert(!__is_literal(NonLiteral), "fail");
49static_assert(!__is_literal(HasDtor), "fail");
50static_assert(!__is_literal(HasNonLiteralBase), "fail");
51static_assert(!__is_literal(HasNonLiteralMember), "fail");
52
53// DR1361 removes the brace-or-equal-initializer bullet so that we can allow:
54extern int f(); // expected-note {{here}}
55struct HasNonConstExprMemInit {
56  int x = f(); // expected-note {{non-constexpr function}}
57  constexpr HasNonConstExprMemInit() {} // expected-error {{never produces a constant expression}}
58  constexpr HasNonConstExprMemInit(int y) : x(y) {} // ok
59};
60static_assert(__is_literal(HasNonConstExprMemInit), "fail");
61
62class HasConstExprCtor {
63  int x;
64public:
65  constexpr HasConstExprCtor(int x) : x(x) {}
66};
67template <typename T> class HasConstExprCtorTemplate {
68  T x;
69public:
70  template <typename U> constexpr HasConstExprCtorTemplate(U y) : x(y) {}
71};
72template <typename T> class HasConstExprCtorT {
73  constexpr HasConstExprCtorT(T) {}
74};
75static_assert(__is_literal(HasConstExprCtor), "fail");
76static_assert(__is_literal(HasConstExprCtorTemplate<int>), "fail");
77static_assert(__is_literal(HasConstExprCtorT<NonLiteral>), "fail");
78