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++2a %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
6
7 #if __cplusplus >= 201103L
8 namespace dr2338 { // dr2338: 12
9 namespace B {
10 enum E : bool { Zero, One };
11 static_assert((int)(E)2 == 1, "");
12 } // namespace B
13 namespace D {
14 enum class E : bool { Zero, One };
15 static_assert((int)(E)2 == 1, "");
16 } // namespace D
17 } // namespace dr2338
18 #endif
19
20 namespace dr2346 { // dr2346: 11
test()21 void test() {
22 const int i2 = 0;
23 extern void h2b(int x = i2 + 0); // ok, not odr-use
24 }
25 }
26
27 namespace dr2352 { // dr2352: 10
28 int **p;
f1()29 const int *const *const &f1() { return p; }
f2()30 int *const *const &f2() { return p; }
f3()31 int **const &f3() { return p; }
32
f4()33 const int **const &f4() { return p; } // expected-error {{reference to type 'const int **const' could not bind to an lvalue of type 'int **'}}
f5()34 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}}
35
36 // FIXME: We permit this as a speculative defect resolution, allowing
37 // qualification conversions when forming a glvalue conditional expression.
38 const int * const * const q = 0;
39 __typeof(&(true ? p : q)) x = &(true ? p : q);
40
41 // FIXME: Should we compute the composite pointer type here and produce an
42 // lvalue of type 'const int *const * const'?
43 const int * const * r;
44 void *y = &(true ? p : r); // expected-error {{rvalue of type 'const int *const *'}}
45
46 // FIXME: We order these as a speculative defect resolution.
47 void f(const int * const * const &r);
48 #if __cplusplus >= 201103L
49 constexpr
50 #endif
f(int * const * const & r)51 int *const *const &f(int * const * const &r) { return r; }
52
53 // No temporary is created here.
54 int *const *const &check_f = f(p);
55 #if __cplusplus >= 201103L
56 static_assert(&p == &check_f, "");
57 #endif
58 }
59
60 namespace dr2353 { // dr2353: 9
61 struct X {
62 static const int n = 0;
63 };
64
65 // CHECK: FunctionDecl {{.*}} use
use(X x)66 int use(X x) {
67 // CHECK: MemberExpr {{.*}} .n
68 // CHECK-NOT: non_odr_use
69 // CHECK: DeclRefExpr {{.*}} 'x'
70 // CHECK-NOT: non_odr_use
71 return *&x.n;
72 }
73 #pragma clang __debug dump use
74
75 // CHECK: FunctionDecl {{.*}} not_use
not_use(X x)76 int not_use(X x) {
77 // CHECK: MemberExpr {{.*}} .n {{.*}} non_odr_use_constant
78 // CHECK: DeclRefExpr {{.*}} 'x'
79 return x.n;
80 }
81 #pragma clang __debug dump not_use
82
83 // CHECK: FunctionDecl {{.*}} not_use_2
not_use_2(X * x)84 int not_use_2(X *x) {
85 // CHECK: MemberExpr {{.*}} ->n {{.*}} non_odr_use_constant
86 // CHECK: DeclRefExpr {{.*}} 'x'
87 return x->n;
88 }
89 #pragma clang __debug dump not_use_2
90 }
91
92 #if __cplusplus >= 201707L
93 // Otherwise, if the qualified-id std::tuple_size<E> names a complete class
94 // type **with a member value**, the expression std::tuple_size<E>::value shall
95 // be a well-formed integral constant expression
96 namespace dr2386 { // dr2386: 9
97 struct Bad1 { int a, b; };
98 struct Bad2 { int a, b; };
99 } // namespace dr2386
100 namespace std {
101 template <typename T> struct tuple_size;
102 template <> struct std::tuple_size<dr2386::Bad1> {};
103 template <> struct std::tuple_size<dr2386::Bad2> {
104 static const int value = 42;
105 };
106 } // namespace std
107 namespace dr2386 {
no_value()108 void no_value() { auto [x, y] = Bad1(); }
wrong_value()109 void wrong_value() { auto [x, y] = Bad2(); } // expected-error {{decomposes into 42 elements}}
110 } // namespace dr2386
111 #endif
112
113 namespace dr2387 { // dr2387: 9
114 #if __cplusplus >= 201402L
115 template<int> int a = 0;
116 extern template int a<0>; // ok
117
118 template<int> static int b = 0;
119 extern template int b<0>; // expected-error {{internal linkage}}
120
121 template<int> const int c = 0;
122 extern template const int c<0>; // ok, has external linkage despite 'const'
123
124 template<typename T> T d = 0;
125 extern template int d<int>;
126 extern template const int d<const int>;
127 #endif
128 }
129
130 #if __cplusplus >= 201103L
131 namespace dr2303 { // dr2303: 12
132 template <typename... T>
133 struct A;
134 template <>
135 struct A<> {};
136 template <typename T, typename... Ts>
137 struct A<T, Ts...> : A<Ts...> {};
138 struct B : A<int, int> {};
139 struct C : A<int, int>, A<int> {}; // expected-warning {{direct base 'A<int>' is inaccessible}}
140 struct D : A<int>, A<int, int> {}; // expected-warning {{direct base 'A<int>' is inaccessible}}
141 struct E : A<int, int> {};
142 struct F : B, E {};
143
144 template <typename... T>
f(const A<T...> &)145 void f(const A<T...> &) {
146 static_assert(sizeof...(T) == 2, "Should only match A<int,int>");
147 }
148 template <typename... T>
149 void f2(const A<T...> *);
150
g()151 void g() {
152 f(B{}); // This is no longer ambiguous.
153 B b;
154 f2(&b);
155 f(C{});
156 f(D{});
157 f(F{}); // expected-error {{ambiguous conversion from derived class}}
158 }
159 } //namespace dr2303
160 #endif
161