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
>
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> {};
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
...> *);
30 f(B
{}); // This is no longer ambiguous.
35 f(F
{}); // expected-error {{ambiguous conversion from derived class}}
42 #if __cplusplus >= 201103L
43 namespace dr2338
{ // dr2338: 12
45 enum E
: bool { Zero
, One
};
46 static_assert((int)(E
)2 == 1, "");
49 enum class E
: bool { Zero
, One
};
50 static_assert((int)(E
)2 == 1, "");
55 namespace dr2346
{ // dr2346: 11
58 extern void h2b(int x
= i2
+ 0); // ok, not odr-use
62 namespace dr2352
{ // dr2352: 10
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
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
, "");
95 namespace dr2353
{ // dr2353: 9
97 static const int n
= 0;
100 // CHECK: FunctionDecl {{.*}} use
102 // CHECK: MemberExpr {{.*}} .n
103 // CHECK-NOT: non_odr_use
104 // CHECK: DeclRefExpr {{.*}} 'x'
105 // CHECK-NOT: non_odr_use
108 #pragma clang __debug dump use
110 // CHECK: FunctionDecl {{.*}} not_use
112 // CHECK: MemberExpr {{.*}} .n {{.*}} non_odr_use_constant
113 // CHECK: DeclRefExpr {{.*}} 'x'
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'
124 #pragma clang __debug dump not_use_2
127 #if __cplusplus >= 201402L
128 namespace dr2358
{ // dr2358: 16
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}}
137 namespace dr2370
{ // dr2370: no
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
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;
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
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>;
191 namespace dr2394
{ // dr2394: 15
196 // Now allowed to default-init B.
197 struct B
{ const A a
; };
202 namespace dr2396
{ // dr2396: no
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
226 } // namespace dr2397