1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
5 static_assert(__is_literal(int), "fail");
6 static_assert(__is_literal_type(int), "fail"); // alternate spelling for GCC
7 static_assert(__is_literal(void*), "fail");
9 static_assert(__is_literal(E
), "fail");
10 static_assert(__is_literal(decltype(E1
)), "fail");
12 static_assert(__is_literal(IAR
), "fail");
13 typedef int Vector
__attribute__((vector_size(16)));
14 typedef int VectorExt
__attribute__((ext_vector_type(4)));
15 static_assert(__is_literal(Vector
), "fail");
16 static_assert(__is_literal(VectorExt
), "fail");
18 // C++0x [basic.types]p10:
19 // A type is a literal type if it is:
21 // -- a class type that has all of the following properties:
22 // -- it has a trivial destructor
23 // -- every constructor call and full-expression in the
24 // brace-or-equal-initializers for non-static data members (if an) is
25 // a constant expression,
26 // -- it is an aggregate type or has at least one constexpr constructor
27 // or constructor template that is not a copy or move constructor, and
28 // [DR1452 adds class types with trivial default constructors to
30 // -- it has all non-static data members and base classes of literal
40 struct HasDtor
{ ~HasDtor(); };
42 class NonAggregate
{ int x
; };
43 struct NonLiteral
{ NonLiteral(); };
44 struct HasNonLiteralBase
: NonLiteral
{};
45 struct HasNonLiteralMember
{ HasDtor x
; };
47 static_assert(__is_literal(Empty
), "fail");
48 static_assert(__is_literal(LiteralType
), "fail");
49 static_assert(__is_literal(NonAggregate
), "fail");
50 static_assert(!__is_literal(NonLiteral
), "fail");
51 static_assert(!__is_literal(HasDtor
), "fail");
52 static_assert(!__is_literal(HasNonLiteralBase
), "fail");
53 static_assert(!__is_literal(HasNonLiteralMember
), "fail");
55 // DR1361 removes the brace-or-equal-initializer bullet so that we can allow:
56 extern int f(); // expected-note {{here}}
57 struct HasNonConstExprMemInit
{
58 int x
= f(); // expected-note {{non-constexpr function}}
59 constexpr HasNonConstExprMemInit() {} // expected-error {{never produces a constant expression}}
60 constexpr HasNonConstExprMemInit(int y
) : x(y
) {} // ok
62 static_assert(__is_literal(HasNonConstExprMemInit
), "fail");
64 class HasConstExprCtor
{
67 constexpr HasConstExprCtor(int x
) : x(x
) {}
69 template <typename T
> class HasConstExprCtorTemplate
{
72 template <typename U
> constexpr HasConstExprCtorTemplate(U y
) : x(y
) {}
74 template <typename T
> class HasConstExprCtorT
{
75 constexpr HasConstExprCtorT(T
) {}
77 static_assert(__is_literal(HasConstExprCtor
), "fail");
78 static_assert(__is_literal(HasConstExprCtorTemplate
<int>), "fail");
79 static_assert(__is_literal(HasConstExprCtorT
<NonLiteral
>), "fail");
82 #if __cplusplus >= 202003L
89 constexpr Data() : x
{} {}
95 constexpr opt() : data
{} {}
96 constexpr ~opt() { if (engaged
) data
.data
.~T(); }
101 consteval
void foo() {