1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++2a -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6 
7 #if __cplusplus < 201103L
8 // expected-error@+1 {{variadic macro}}
9 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
10 #endif
11 
12 namespace dr1813 { // dr1813: 7
13   struct B { int i; };
14   struct C : B {};
15   struct D : C {};
16   struct E : D { char : 4; };
17 
18   static_assert(__is_standard_layout(B), "");
19   static_assert(__is_standard_layout(C), "");
20   static_assert(__is_standard_layout(D), "");
21   static_assert(!__is_standard_layout(E), "");
22 
23   struct Q {};
24   struct S : Q {};
25   struct T : Q {};
26   struct U : S, T {};
27 
28   static_assert(__is_standard_layout(Q), "");
29   static_assert(__is_standard_layout(S), "");
30   static_assert(__is_standard_layout(T), "");
31   static_assert(!__is_standard_layout(U), "");
32 }
33 
34 namespace dr1814 { // dr1814: yes
35 #if __cplusplus >= 201103L
test()36   void test() {
37     auto lam = [](int x = 42) { return x; };
38   }
39 #endif
40 }
41 
42 namespace dr1815 { // dr1815: no
43 #if __cplusplus >= 201402L
44   // FIXME: needs codegen test
45   struct A { int &&r = 0; }; // expected-note {{default member init}}
46   A a = {}; // FIXME expected-warning {{not supported}}
47 
48   struct B { int &&r = 0; }; // expected-error {{binds to a temporary}} expected-note {{default member init}}
49   B b; // expected-note {{here}}
50 #endif
51 }
52 
53 namespace dr1872 { // dr1872: 9
54 #if __cplusplus >= 201103L
55   template<typename T> struct A : T {
fdr1872::A56     constexpr int f() const { return 0; }
57   };
58   struct X {};
59   struct Y { virtual int f() const; };
60   struct Z : virtual X {};
61 
62   constexpr int x = A<X>().f();
63   constexpr int y = A<Y>().f();
64 #if __cplusplus <= 201703L
65   // expected-error@-2 {{constant expression}} expected-note@-2 {{call to virtual function}}
66 #else
67   static_assert(y == 0);
68 #endif
69   // Note, this is invalid even though it would not use virtual dispatch.
70   constexpr int y2 = A<Y>().A<Y>::f();
71 #if __cplusplus <= 201703L
72   // expected-error@-2 {{constant expression}} expected-note@-2 {{call to virtual function}}
73 #else
74   static_assert(y == 0);
75 #endif
76   constexpr int z = A<Z>().f(); // expected-error {{constant expression}} expected-note {{non-literal type}}
77 #endif
78 }
79 
80 namespace dr1881 { // dr1881: 7
81   struct A { int a : 4; };
82   struct B : A { int b : 3; };
83   static_assert(__is_standard_layout(A), "");
84   static_assert(!__is_standard_layout(B), "");
85 
86   struct C { int : 0; };
87   struct D : C { int : 0; };
88   static_assert(__is_standard_layout(C), "");
89   static_assert(!__is_standard_layout(D), "");
90 }
91 
dr1891()92 void dr1891() { // dr1891: 4
93 #if __cplusplus >= 201103L
94   int n;
95   auto a = []{}; // expected-note 0-4{{}}
96   auto b = [=]{ return n; }; // expected-note 0-4{{}}
97   typedef decltype(a) A;
98   typedef decltype(b) B;
99 
100   static_assert(!__has_trivial_constructor(A), "");
101 #if __cplusplus > 201703L
102   // expected-error@-2 {{failed}}
103 #endif
104   static_assert(!__has_trivial_constructor(B), "");
105 
106   // C++20 allows default construction for non-capturing lambdas (P0624R2).
107   A x;
108 #if __cplusplus <= 201703L
109   // expected-error@-2 {{no matching constructor}}
110 #endif
111   B y; // expected-error {{no matching constructor}}
112 
113   // C++20 allows assignment for non-capturing lambdas (P0624R2).
114   a = a;
115   a = static_cast<A&&>(a);
116 #if __cplusplus <= 201703L
117   // expected-error@-3 {{copy assignment operator is implicitly deleted}}
118   // expected-error@-3 {{copy assignment operator is implicitly deleted}}
119 #endif
120   b = b; // expected-error {{copy assignment operator is implicitly deleted}}
121   b = static_cast<B&&>(b); // expected-error {{copy assignment operator is implicitly deleted}}
122 #endif
123 }
124