Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr23xx.cpp
blob6cb10067739f8eb415439cd964b57ef2b4e781cf
1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1
2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
4 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
5 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
6 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
8 #if __cplusplus >= 201103L
9 namespace dr2303 { // dr2303: 12
10 template <typename... T>
11 struct A;
12 template <>
13 struct A<> {};
14 template <typename T, typename... Ts>
15 struct A<T, Ts...> : A<Ts...> {};
16 struct B : A<int, int> {};
17 struct C : A<int, int>, A<int> {}; // expected-warning {{direct base 'A<int>' is inaccessible}}
18 struct D : A<int>, A<int, int> {}; // expected-warning {{direct base 'A<int>' is inaccessible}}
19 struct E : A<int, int> {};
20 struct F : B, E {};
22 template <typename... T>
23 void f(const A<T...> &) {
24 static_assert(sizeof...(T) == 2, "Should only match A<int,int>");
26 template <typename... T>
27 void f2(const A<T...> *);
29 void g() {
30 f(B{}); // This is no longer ambiguous.
31 B b;
32 f2(&b);
33 f(C{});
34 f(D{});
35 f(F{}); // expected-error {{ambiguous conversion from derived class}}
37 } //namespace dr2303
38 #endif
40 // dr2331: na
42 #if __cplusplus >= 201103L
43 namespace dr2338 { // dr2338: 12
44 namespace B {
45 enum E : bool { Zero, One };
46 static_assert((int)(E)2 == 1, "");
47 } // namespace B
48 namespace D {
49 enum class E : bool { Zero, One };
50 static_assert((int)(E)2 == 1, "");
51 } // namespace D
52 } // namespace dr2338
53 #endif
55 namespace dr2346 { // dr2346: 11
56 void test() {
57 const int i2 = 0;
58 extern void h2b(int x = i2 + 0); // ok, not odr-use
62 namespace dr2352 { // dr2352: 10
63 int **p;
64 const int *const *const &f1() { return p; }
65 int *const *const &f2() { return p; }
66 int **const &f3() { return p; }
68 const int **const &f4() { return p; } // expected-error {{reference to type 'const int **const' could not bind to an lvalue of type 'int **'}}
69 const int *const *&f5() { return p; } // expected-error {{binding reference of type 'const int *const *' to value of type 'int **' not permitted due to incompatible qualifiers}}
71 // FIXME: We permit this as a speculative defect resolution, allowing
72 // qualification conversions when forming a glvalue conditional expression.
73 const int * const * const q = 0;
74 __typeof(&(true ? p : q)) x = &(true ? p : q);
76 // FIXME: Should we compute the composite pointer type here and produce an
77 // lvalue of type 'const int *const * const'?
78 const int * const * r;
79 void *y = &(true ? p : r); // expected-error {{rvalue of type 'const int *const *'}}
81 // FIXME: We order these as a speculative defect resolution.
82 void f(const int * const * const &r);
83 #if __cplusplus >= 201103L
84 constexpr
85 #endif
86 int *const *const &f(int * const * const &r) { return r; }
88 // No temporary is created here.
89 int *const *const &check_f = f(p);
90 #if __cplusplus >= 201103L
91 static_assert(&p == &check_f, "");
92 #endif
95 namespace dr2353 { // dr2353: 9
96 struct X {
97 static const int n = 0;
100 // CHECK: FunctionDecl {{.*}} use
101 int use(X x) {
102 // CHECK: MemberExpr {{.*}} .n
103 // CHECK-NOT: non_odr_use
104 // CHECK: DeclRefExpr {{.*}} 'x'
105 // CHECK-NOT: non_odr_use
106 return *&x.n;
108 #pragma clang __debug dump use
110 // CHECK: FunctionDecl {{.*}} not_use
111 int not_use(X x) {
112 // CHECK: MemberExpr {{.*}} .n {{.*}} non_odr_use_constant
113 // CHECK: DeclRefExpr {{.*}} 'x'
114 return x.n;
116 #pragma clang __debug dump not_use
118 // CHECK: FunctionDecl {{.*}} not_use_2
119 int not_use_2(X *x) {
120 // CHECK: MemberExpr {{.*}} ->n {{.*}} non_odr_use_constant
121 // CHECK: DeclRefExpr {{.*}} 'x'
122 return x->n;
124 #pragma clang __debug dump not_use_2
127 #if __cplusplus >= 201402L
128 namespace dr2358 { // dr2358: 16
129 void f2() {
130 int i = 1;
131 void g1(int = [xxx=1] { return xxx; }()); // OK
132 void g2(int = [xxx=i] { return xxx; }()); // expected-error {{default argument references local variable 'i' of enclosing function}}
135 #endif
137 namespace dr2370 { // dr2370: no
138 namespace N {
139 typedef int type;
140 void g(type);
141 void h(type);
142 } // namespace N
143 class C {
144 typedef N::type N_type;
145 // FIXME: `type` should be searched for in N
146 // friend void N::g(type);
147 friend void N::h(N_type);
149 } // namespace dr2370
151 #if __cplusplus >= 201707L
152 // Otherwise, if the qualified-id std::tuple_size<E> names a complete class
153 // type **with a member value**, the expression std::tuple_size<E>::value shall
154 // be a well-formed integral constant expression
155 namespace dr2386 { // dr2386: 9
156 struct Bad1 { int a, b; };
157 struct Bad2 { int a, b; };
158 } // namespace dr2386
159 namespace std {
160 template <typename T> struct tuple_size;
161 template <> struct std::tuple_size<dr2386::Bad1> {};
162 template <> struct std::tuple_size<dr2386::Bad2> {
163 static const int value = 42;
165 } // namespace std
166 namespace dr2386 {
167 void no_value() { auto [x, y] = Bad1(); }
168 void wrong_value() { auto [x, y] = Bad2(); } // expected-error {{decomposes into 42 elements}}
169 } // namespace dr2386
170 #endif
172 // dr2385: na
174 namespace dr2387 { // dr2387: 9
175 #if __cplusplus >= 201402L
176 template<int> int a = 0;
177 extern template int a<0>; // ok
179 template<int> static int b = 0;
180 extern template int b<0>; // expected-error {{internal linkage}}
182 template<int> const int c = 0;
183 extern template const int c<0>; // ok, has external linkage despite 'const'
185 template<typename T> T d = 0;
186 extern template int d<int>;
187 extern template const int d<const int>;
188 #endif
191 namespace dr2394 { // dr2394: 15
193 struct A {};
194 const A a;
196 // Now allowed to default-init B.
197 struct B { const A a; };
198 B b;
202 namespace dr2396 { // dr2396: no
203 struct A {
204 struct B;
205 operator B B::*();
207 struct B;
209 // FIXME: per P1787 "Calling a conversion function" example, all of the
210 // examples below are well-formed, with B resolving to A::B, but currently
211 // it's been resolved to dr2396::B.
213 // void f(A a) { a.operator B B::*(); }
214 // void g(A a) { a.operator decltype(B()) B::*(); }
215 // void g2(A a) { a.operator B decltype(B())::*(); }
218 #if __cplusplus >= 201103L
219 namespace dr2397 { // dr2397: 17
220 void foo() {
221 int a[5];
223 auto (&b)[5] = a;
224 auto (*c)[5] = &a;
226 } // namespace dr2397
227 #endif