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 dr1815 { // dr1815: no
35 #if __cplusplus >= 201402L
36   // FIXME: needs codegen test
37   struct A { int &&r = 0; }; // expected-note {{default member init}}
38   A a = {}; // FIXME expected-warning {{not supported}}
39 
40   struct B { int &&r = 0; }; // expected-error {{binds to a temporary}} expected-note {{default member init}}
41   B b; // expected-note {{here}}
42 #endif
43 }
44 
45 namespace dr1872 { // dr1872: 9
46 #if __cplusplus >= 201103L
47   template<typename T> struct A : T {
fdr1872::A48     constexpr int f() const { return 0; }
49   };
50   struct X {};
51   struct Y { virtual int f() const; };
52   struct Z : virtual X {};
53 
54   constexpr int x = A<X>().f();
55   constexpr int y = A<Y>().f();
56 #if __cplusplus <= 201703L
57   // expected-error@-2 {{constant expression}} expected-note@-2 {{call to virtual function}}
58 #else
59   static_assert(y == 0);
60 #endif
61   // Note, this is invalid even though it would not use virtual dispatch.
62   constexpr int y2 = A<Y>().A<Y>::f();
63 #if __cplusplus <= 201703L
64   // expected-error@-2 {{constant expression}} expected-note@-2 {{call to virtual function}}
65 #else
66   static_assert(y == 0);
67 #endif
68   constexpr int z = A<Z>().f(); // expected-error {{constant expression}} expected-note {{non-literal type}}
69 #endif
70 }
71 
72 namespace dr1881 { // dr1881: 7
73   struct A { int a : 4; };
74   struct B : A { int b : 3; };
75   static_assert(__is_standard_layout(A), "");
76   static_assert(!__is_standard_layout(B), "");
77 
78   struct C { int : 0; };
79   struct D : C { int : 0; };
80   static_assert(__is_standard_layout(C), "");
81   static_assert(!__is_standard_layout(D), "");
82 }
83 
dr1891()84 void dr1891() { // dr1891: 4
85 #if __cplusplus >= 201103L
86   int n;
87   auto a = []{}; // expected-note 0-4{{}}
88   auto b = [=]{ return n; }; // expected-note 0-4{{}}
89   typedef decltype(a) A;
90   typedef decltype(b) B;
91 
92   static_assert(!__has_trivial_constructor(A), "");
93 #if __cplusplus > 201703L
94   // expected-error@-2 {{failed}}
95 #endif
96   static_assert(!__has_trivial_constructor(B), "");
97 
98   // C++20 allows default construction for non-capturing lambdas (P0624R2).
99   A x;
100 #if __cplusplus <= 201703L
101   // expected-error@-2 {{no matching constructor}}
102 #endif
103   B y; // expected-error {{no matching constructor}}
104 
105   // C++20 allows assignment for non-capturing lambdas (P0624R2).
106   a = a;
107   a = static_cast<A&&>(a);
108 #if __cplusplus <= 201703L
109   // expected-error@-3 {{copy assignment operator is implicitly deleted}}
110   // expected-error@-3 {{copy assignment operator is implicitly deleted}}
111 #endif
112   b = b; // expected-error {{copy assignment operator is implicitly deleted}}
113   b = static_cast<B&&>(b); // expected-error {{copy assignment operator is implicitly deleted}}
114 #endif
115 }
116