Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr18xx.cpp
blob7ac26737382281e28225ddd271b13d433bb52c0c
1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
7 // RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
9 #if __cplusplus < 201103L
10 // expected-error@+1 {{variadic macro}}
11 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
12 #endif
14 namespace dr1812 { // dr1812: no
15 // NB: dup 1710
16 #if __cplusplus >= 201103L
17 template <typename T> struct A {
18 using B = typename T::C<int>;
19 // expected-error@-1 {{use 'template' keyword to treat 'C' as a dependent template name}}
21 #endif
22 } // namespace dr1812
24 namespace dr1813 { // dr1813: 7
25 struct B { int i; };
26 struct C : B {};
27 struct D : C {};
28 struct E : D { char : 4; };
30 static_assert(__is_standard_layout(B), "");
31 static_assert(__is_standard_layout(C), "");
32 static_assert(__is_standard_layout(D), "");
33 static_assert(!__is_standard_layout(E), "");
35 struct Q {};
36 struct S : Q {};
37 struct T : Q {};
38 struct U : S, T {};
40 static_assert(__is_standard_layout(Q), "");
41 static_assert(__is_standard_layout(S), "");
42 static_assert(__is_standard_layout(T), "");
43 static_assert(!__is_standard_layout(U), "");
46 namespace dr1814 { // dr1814: yes
47 #if __cplusplus >= 201103L
48 void test() {
49 auto lam = [](int x = 42) { return x; };
51 #endif
54 namespace dr1815 { // dr1815: no
55 #if __cplusplus >= 201402L
56 // FIXME: needs codegen test
57 struct A { int &&r = 0; }; // expected-note {{default member init}}
58 A a = {}; // FIXME expected-warning {{not supported}}
60 struct B { int &&r = 0; }; // expected-error {{binds to a temporary}} expected-note {{default member init}}
61 B b; // expected-note {{here}}
62 #endif
65 namespace dr1821 { // dr1821: yes
66 struct A {
67 template <typename> struct B {
68 void f();
70 template <typename T> void B<T>::f(){};
71 // expected-error@-1 {{non-friend class member 'f' cannot have a qualified name}}
73 struct C {
74 void f();
76 void C::f() {}
77 // expected-error@-1 {{non-friend class member 'f' cannot have a qualified name}}
79 } // namespace dr1821
81 namespace dr1822 { // dr1822: yes
82 #if __cplusplus >= 201103L
83 int a;
84 auto x = [] (int a) {
85 #pragma clang __debug dump a // CHECK: ParmVarDecl
87 #endif
90 namespace dr1837 { // dr1837: 3.3
91 #if __cplusplus >= 201103L
92 template <typename T>
93 struct Fish { static const bool value = true; };
95 struct Other {
96 int p();
97 auto q() -> decltype(p()) *;
100 class Outer {
101 friend auto Other::q() -> decltype(this->p()) *; // expected-error {{invalid use of 'this'}}
102 int g();
103 int f() {
104 extern void f(decltype(this->g()) *);
105 struct Inner {
106 static_assert(Fish<decltype(this->g())>::value, ""); // expected-error {{invalid use of 'this'}}
107 enum { X = Fish<decltype(this->f())>::value }; // expected-error {{invalid use of 'this'}}
108 struct Inner2 : Fish<decltype(this->g())> { }; // expected-error {{invalid use of 'this'}}
109 friend void f(decltype(this->g()) *); // expected-error {{invalid use of 'this'}}
110 friend auto Other::q() -> decltype(this->p()) *; // expected-error {{invalid use of 'this'}}
112 return 0;
116 struct A {
117 int f();
118 bool b = [] {
119 struct Local {
120 static_assert(sizeof(this->f()) == sizeof(int), "");
124 #endif
127 namespace dr1872 { // dr1872: 9
128 #if __cplusplus >= 201103L
129 template<typename T> struct A : T {
130 constexpr int f() const { return 0; }
132 struct X {};
133 struct Y { virtual int f() const; };
134 struct Z : virtual X {};
136 constexpr int x = A<X>().f();
137 constexpr int y = A<Y>().f();
138 #if __cplusplus <= 201703L
139 // expected-error@-2 {{constant expression}} expected-note@-2 {{call to virtual function}}
140 #else
141 static_assert(y == 0);
142 #endif
143 // Note, this is invalid even though it would not use virtual dispatch.
144 constexpr int y2 = A<Y>().A<Y>::f();
145 #if __cplusplus <= 201703L
146 // expected-error@-2 {{constant expression}} expected-note@-2 {{call to virtual function}}
147 #else
148 static_assert(y == 0);
149 #endif
150 constexpr int z = A<Z>().f(); // expected-error {{constant expression}} expected-note {{non-literal type}}
151 #endif
154 namespace dr1881 { // dr1881: 7
155 struct A { int a : 4; };
156 struct B : A { int b : 3; };
157 static_assert(__is_standard_layout(A), "");
158 static_assert(!__is_standard_layout(B), "");
160 struct C { int : 0; };
161 struct D : C { int : 0; };
162 static_assert(__is_standard_layout(C), "");
163 static_assert(!__is_standard_layout(D), "");
166 void dr1891() { // dr1891: 4
167 #if __cplusplus >= 201103L
168 int n;
169 auto a = []{}; // expected-note 0-4{{}}
170 auto b = [=]{ return n; }; // expected-note 0-4{{}}
171 typedef decltype(a) A;
172 typedef decltype(b) B;
174 static_assert(!__has_trivial_constructor(A), "");
175 #if __cplusplus > 201703L
176 // expected-error@-2 {{failed}}
177 #endif
178 static_assert(!__has_trivial_constructor(B), "");
180 // C++20 allows default construction for non-capturing lambdas (P0624R2).
181 A x;
182 #if __cplusplus <= 201703L
183 // expected-error@-2 {{no matching constructor}}
184 #endif
185 B y; // expected-error {{no matching constructor}}
187 // C++20 allows assignment for non-capturing lambdas (P0624R2).
188 a = a;
189 a = static_cast<A&&>(a);
190 #if __cplusplus <= 201703L
191 // expected-error@-3 {{copy assignment operator is implicitly deleted}}
192 // expected-error@-3 {{copy assignment operator is implicitly deleted}}
193 #endif
194 b = b; // expected-error {{copy assignment operator is implicitly deleted}}
195 b = static_cast<B&&>(b); // expected-error {{copy assignment operator is implicitly deleted}}
196 #endif
199 namespace dr1894 { // dr1894: 3.8
200 // NB: reusing part of dr407 test
201 namespace A {
202 struct S {};
204 namespace B {
205 typedef int S;
207 namespace E {
208 typedef A::S S;
209 using A::S;
210 struct S s;
212 namespace F {
213 typedef A::S S;
215 namespace G {
216 using namespace A;
217 using namespace F;
218 struct S s;
220 namespace H {
221 using namespace F;
222 using namespace A;
223 struct S s;