1 | // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors |
2 | // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors |
3 | // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors |
4 | // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors |
5 | |
6 | // FIXME: __SIZE_TYPE__ expands to 'long long' on some targets. |
7 | __extension__ typedef __SIZE_TYPE__ size_t; |
8 | |
9 | namespace std { struct type_info; } |
10 | |
11 | namespace dr400 { // dr400: yes |
12 | struct A { int a; struct a {}; }; // expected-note 2{{conflicting}} expected-note {{ambiguous}} |
13 | struct B { int a; struct a {}; }; // expected-note 2{{target}} expected-note {{ambiguous}} |
14 | struct C : A, B { using A::a; struct a b; }; |
15 | struct D : A, B { using A::a; using B::a; struct a b; }; // expected-error 2{{conflicts}} |
16 | struct E : A, B { struct a b; }; // expected-error {{found in multiple base classes}} |
17 | } |
18 | |
19 | namespace dr401 { // dr401: yes |
20 | template<class T, class U = typename T::type> class A : public T {}; // expected-error {{protected}} expected-error 2{{private}} |
21 | |
22 | class B { |
23 | protected: |
24 | typedef int type; // expected-note {{protected}} |
25 | #if __cplusplus == 199711L |
26 | // expected-note@-2 {{protected}} |
27 | #endif |
28 | }; |
29 | |
30 | class C { |
31 | typedef int type; // expected-note {{private}} |
32 | friend class A<C>; // expected-note {{default argument}} |
33 | }; |
34 | |
35 | class D { |
36 | typedef int type; // expected-note {{private}} |
37 | friend class A<D, int>; |
38 | }; |
39 | |
40 | A<B> *b; // expected-note {{default argument}} |
41 | A<D> *d; // expected-note {{in instantiation of default argument}} |
42 | |
43 | struct E { |
44 | template<class T, class U = typename T::type> class A : public T {}; |
45 | }; |
46 | class F { |
47 | typedef int type; |
48 | friend class E; |
49 | }; |
50 | E::A<F> eaf; // ok, default argument is in befriended context |
51 | |
52 | // FIXME: Why do we get different diagnostics in C++11 onwards here? We seem |
53 | // to not treat the default template argument as a SFINAE context in C++98. |
54 | template<class T, class U = typename T::type> void f(T) {} |
55 | void g(B b) { f(b); } |
56 | #if __cplusplus < 201103L |
57 | // expected-error@-3 0-1{{extension}} expected-error@-3 {{protected}} expected-note@-3 {{instantiation}} |
58 | // expected-note@-3 {{substituting}} |
59 | #else |
60 | // expected-error@-5 {{no matching}} expected-note@-6 {{protected}} |
61 | #endif |
62 | } |
63 | |
64 | namespace dr403 { // dr403: yes |
65 | namespace A { |
66 | struct S {}; |
67 | int f(void*); |
68 | } |
69 | template<typename T> struct X {}; |
70 | typedef struct X<A::S>::X XS; |
71 | XS *p; |
72 | int k = f(p); // ok, finds A::f, even though type XS is a typedef-name |
73 | // referring to an elaborated-type-specifier naming a |
74 | // injected-class-name, which is about as far from a |
75 | // template-id as we can make it. |
76 | } |
77 | |
78 | // dr404: na |
79 | // (NB: also sup 594) |
80 | |
81 | namespace dr406 { // dr406: yes |
82 | typedef struct { |
83 | static int n; // expected-error {{static data member 'n' not allowed in anonymous struct}} |
84 | } A; |
85 | } |
86 | |
87 | namespace dr407 { // dr407: 3.8 |
88 | struct S; |
89 | typedef struct S S; |
90 | void f() { |
91 | struct S *p; |
92 | { |
93 | typedef struct S S; // expected-note {{here}} |
94 | struct S *p; // expected-error {{typedef 'S' cannot be referenced with a struct specifier}} |
95 | } |
96 | } |
97 | struct S {}; |
98 | |
99 | namespace UsingDir { |
100 | namespace A { |
101 | struct S {}; // expected-note {{found}} |
102 | } |
103 | namespace B { |
104 | typedef int S; // expected-note {{found}} |
105 | } |
106 | namespace C { |
107 | using namespace A; |
108 | using namespace B; |
109 | struct S s; // expected-error {{ambiguous}} |
110 | } |
111 | namespace D { |
112 | using A::S; |
113 | typedef struct S S; |
114 | struct S s; |
115 | } |
116 | namespace E { |
117 | // The standard doesn't say whether this is valid. We interpret |
118 | // DR407 as meaning "if lookup finds both a tag and a typedef with the |
119 | // same type, then it's OK in an elaborated-type-specifier". |
120 | typedef A::S S; |
121 | using A::S; |
122 | struct S s; |
123 | } |
124 | namespace F { |
125 | typedef A::S S; |
126 | } |
127 | // The standard doesn't say what to do in these cases either. |
128 | namespace G { |
129 | using namespace A; |
130 | using namespace F; |
131 | struct S s; |
132 | } |
133 | namespace H { |
134 | using namespace F; |
135 | using namespace A; |
136 | struct S s; |
137 | } |
138 | } |
139 | } |
140 | |
141 | namespace dr408 { // dr408: 3.4 |
142 | template<int N> void g() { int arr[N != 1 ? 1 : -1]; } |
143 | template<> void g<2>() { } |
144 | |
145 | template<typename T> struct S { |
146 | static int i[]; |
147 | void f(); |
148 | }; |
149 | template<typename T> int S<T>::i[] = { 1 }; |
150 | |
151 | template<typename T> void S<T>::f() { |
152 | g<sizeof (i) / sizeof (int)>(); |
153 | } |
154 | template<> int S<int>::i[] = { 1, 2 }; |
155 | template void S<int>::f(); // uses g<2>(), not g<1>(). |
156 | |
157 | |
158 | template<typename T> struct R { |
159 | static int arr[]; |
160 | void f(); |
161 | }; |
162 | template<typename T> int R<T>::arr[1]; |
163 | template<typename T> void R<T>::f() { |
164 | int arr[sizeof(arr) != sizeof(int) ? 1 : -1]; |
165 | } |
166 | template<> int R<int>::arr[2]; |
167 | template void R<int>::f(); |
168 | } |
169 | |
170 | namespace dr409 { // dr409: yes |
171 | template<typename T> struct A { |
172 | typedef int B; |
173 | B b1; |
174 | A::B b2; |
175 | A<T>::B b3; |
176 | A<T*>::B b4; // expected-error {{missing 'typename'}} |
177 | }; |
178 | } |
179 | |
180 | namespace dr410 { // dr410: no |
181 | template<class T> void f(T); |
182 | void g(int); |
183 | namespace M { |
184 | template<class T> void h(T); |
185 | template<class T> void i(T); |
186 | struct A { |
187 | friend void f<>(int); |
188 | friend void h<>(int); |
189 | friend void g(int); |
190 | template<class T> void i(T); |
191 | friend void i<>(int); |
192 | private: |
193 | static void z(); // expected-note {{private}} |
194 | }; |
195 | |
196 | template<> void h(int) { A::z(); } |
197 | // FIXME: This should be ill-formed. The member A::i<> is befriended, |
198 | // not this function. |
199 | template<> void i(int) { A::z(); } |
200 | } |
201 | template<> void f(int) { M::A::z(); } |
202 | void g(int) { M::A::z(); } // expected-error {{private}} |
203 | } |
204 | |
205 | // dr412 is in its own file. |
206 | |
207 | namespace dr413 { // dr413: yes |
208 | struct S { |
209 | int a; |
210 | int : 17; |
211 | int b; |
212 | }; |
213 | S s = { 1, 2, 3 }; // expected-error {{excess elements}} |
214 | |
215 | struct E {}; |
216 | struct T { // expected-note {{here}} |
217 | int a; |
218 | E e; |
219 | int b; |
220 | }; |
221 | T t1 = { 1, {}, 2 }; |
222 | T t2 = { 1, 2 }; // expected-error {{aggregate with no elements requires explicit braces}} |
223 | } |
224 | |
225 | namespace dr414 { // dr414: dup 305 |
226 | struct X {}; |
227 | void f() { |
228 | X x; |
229 | struct X {}; |
230 | x.~X(); |
231 | } |
232 | } |
233 | |
234 | namespace dr415 { // dr415: yes |
235 | template<typename T> void f(T, ...) { T::error; } |
236 | void f(int, int); |
237 | void g() { f(0, 0); } // ok |
238 | } |
239 | |
240 | namespace dr416 { // dr416: yes |
241 | extern struct A a; |
242 | int &operator+(const A&, const A&); |
243 | int &k = a + a; |
244 | struct A { float &operator+(A&); }; |
245 | float &f = a + a; |
246 | } |
247 | |
248 | namespace dr417 { // dr417: no |
249 | struct A; |
250 | struct dr417::A {}; // expected-warning {{extra qualification}} |
251 | struct B { struct X; }; |
252 | struct C : B {}; |
253 | struct C::X {}; // expected-error {{no struct named 'X' in 'dr417::C'}} |
254 | struct B::X { struct Y; }; |
255 | struct C::X::Y {}; // ok! |
256 | namespace N { |
257 | struct D; |
258 | struct E; |
259 | struct F; |
260 | struct H; |
261 | } |
262 | // FIXME: This is ill-formed. |
263 | using N::D; |
264 | struct dr417::D {}; // expected-warning {{extra qualification}} |
265 | using namespace N; |
266 | struct dr417::E {}; // expected-warning {{extra qualification}} expected-error {{no struct named 'E'}} |
267 | struct N::F {}; |
268 | struct G; |
269 | using N::H; |
270 | namespace M { |
271 | struct dr417::G {}; // expected-error {{namespace 'M' does not enclose}} |
272 | struct dr417::H {}; // expected-error {{namespace 'M' does not enclose}} |
273 | } |
274 | } |
275 | |
276 | namespace dr420 { // dr420: yes |
277 | template<typename T> struct ptr { |
278 | T *operator->() const; |
279 | T &operator*() const; |
280 | }; |
281 | template<typename T, typename P> void test(P p) { |
282 | p->~T(); |
283 | p->T::~T(); |
284 | (*p).~T(); |
285 | (*p).T::~T(); |
286 | } |
287 | struct X {}; |
288 | template void test<int>(int*); |
289 | template void test<int>(ptr<int>); |
290 | template void test<X>(X*); |
291 | template void test<X>(ptr<X>); |
292 | |
293 | template<typename T> |
294 | void test2(T p) { |
295 | p->template Y<int>::~Y<int>(); |
296 | p->~Y<int>(); |
297 | // FIXME: This is ill-formed, but this diagnostic is terrible. We should |
298 | // reject this in the parser. |
299 | p->template ~Y<int>(); // expected-error 2{{no member named '~typename Y<int>'}} |
300 | } |
301 | template<typename T> struct Y {}; |
302 | template void test2(Y<int>*); // expected-note {{instantiation}} |
303 | template void test2(ptr<Y<int> >); // expected-note {{instantiation}} |
304 | |
305 | void test3(int *p, ptr<int> q) { |
306 | typedef int Int; |
307 | p->~Int(); |
308 | q->~Int(); |
309 | p->Int::~Int(); |
310 | q->Int::~Int(); |
311 | } |
312 | |
313 | #if __cplusplus >= 201103L |
314 | template<typename T> using id = T; |
315 | struct A { template<typename T> using id = T; }; |
316 | void test4(int *p, ptr<int> q) { |
317 | p->~id<int>(); |
318 | q->~id<int>(); |
319 | p->id<int>::~id<int>(); |
320 | q->id<int>::~id<int>(); |
321 | p->template id<int>::~id<int>(); // expected-error {{'template' keyword not permitted here}} expected-error {{base type 'int' is not a struct}} |
322 | q->template id<int>::~id<int>(); // expected-error {{'template' keyword not permitted here}} expected-error {{base type 'int' is not a struct}} |
323 | p->A::template id<int>::~id<int>(); |
324 | q->A::template id<int>::~id<int>(); |
325 | } |
326 | #endif |
327 | } |
328 | |
329 | namespace dr421 { // dr421: yes |
330 | struct X { X(); int n; int &r; }; |
331 | int *p = &X().n; // expected-error-re {{{{taking the address of a temporary|cannot take the address of an rvalue}}}} |
332 | int *q = &X().r; |
333 | } |
334 | |
335 | namespace dr422 { // dr422: yes |
336 | template<typename T, typename U> void f() { |
337 | typedef T type; // expected-note {{prev}} |
338 | typedef U type; // expected-error {{redef}} |
339 | } |
340 | template void f<int, int>(); |
341 | template void f<int, char>(); // expected-note {{instantiation}} |
342 | } |
343 | |
344 | namespace dr423 { // dr423: yes |
345 | template<typename T> struct X { operator T&(); }; |
346 | void f(X<int> x) { x += 1; } |
347 | } |
348 | |
349 | namespace dr424 { // dr424: yes |
350 | struct A { |
351 | typedef int N; // expected-note {{previous}} |
352 | typedef int N; // expected-error {{redefinition}} |
353 | |
354 | struct X; |
355 | typedef X X; // expected-note {{previous}} |
356 | struct X {}; |
357 | |
358 | struct X *p; |
359 | struct A::X *q; |
360 | X *r; |
361 | |
362 | typedef X X; // expected-error {{redefinition}} |
363 | }; |
364 | struct B { |
365 | typedef int N; |
366 | }; |
367 | struct C : B { |
368 | typedef int N; // expected-note {{previous}} |
369 | typedef int N; // expected-error {{redefinition}} |
370 | }; |
371 | } |
372 | |
373 | namespace dr425 { // dr425: yes |
374 | struct A { template<typename T> operator T() const; } a; |
375 | float f = 1.0f * a; // expected-error {{ambiguous}} expected-note 5+{{built-in candidate}} |
376 | |
377 | template<typename T> struct is_float; |
378 | template<> struct is_float<float> { typedef void type; }; |
379 | |
380 | struct B { |
381 | template<typename T, typename U = typename is_float<T>::type> operator T() const; // expected-error 0-1{{extension}} |
382 | } b; |
383 | float g = 1.0f * b; // ok |
384 | } |
385 | |
386 | namespace dr427 { // dr427: yes |
387 | struct B {}; |
388 | struct D : public B { |
389 | D(B &) = delete; // expected-error 0-1{{extension}} expected-note {{deleted}} |
390 | }; |
391 | |
392 | extern D d1; |
393 | B &b = d1; |
394 | const D &d2 = static_cast<const D&>(b); |
395 | const D &d3 = (const D&)b; |
396 | const D &d4(b); // expected-error {{deleted}} |
397 | } |
398 | |
399 | namespace dr428 { // dr428: yes |
400 | template<typename T> T make(); |
401 | extern struct X x; // expected-note 5{{forward declaration}} |
402 | void f() { |
403 | throw void(); // expected-error {{cannot throw}} |
404 | throw make<void*>(); |
405 | throw make<const volatile void*>(); |
406 | throw x; // expected-error {{cannot throw}} |
407 | throw make<X&>(); // expected-error {{cannot throw}} |
408 | throw make<X*>(); // expected-error {{cannot throw}} |
409 | throw make<const volatile X&>(); // expected-error {{cannot throw}} |
410 | throw make<const volatile X*>(); // expected-error {{cannot throw}} |
411 | } |
412 | } |
413 | |
414 | namespace dr429 { // dr429: yes c++11 |
415 | // FIXME: This rule is obviously intended to apply to C++98 as well. |
416 | struct A { |
417 | static void *operator new(size_t, size_t); |
418 | static void operator delete(void*, size_t); |
419 | } *a = new (0) A; |
420 | #if __cplusplus >= 201103L |
421 | // expected-error@-2 {{'new' expression with placement arguments refers to non-placement 'operator delete'}} |
422 | // expected-note@-4 {{here}} |
423 | #endif |
424 | struct B { |
425 | static void *operator new(size_t, size_t); |
426 | static void operator delete(void*); |
427 | static void operator delete(void*, size_t); |
428 | } *b = new (0) B; // ok, second delete is not a non-placement deallocation function |
429 | } |
430 | |
431 | namespace dr430 { // dr430: yes c++11 |
432 | // resolved by n2239 |
433 | // FIXME: This should apply in C++98 too. |
434 | void f(int n) { |
435 | int a[] = { n++, n++, n++ }; |
436 | #if __cplusplus < 201103L |
437 | // expected-warning@-2 {{multiple unsequenced modifications to 'n'}} |
438 | #endif |
439 | } |
440 | } |
441 | |
442 | namespace dr431 { // dr431: yes |
443 | struct A { |
444 | template<typename T> T *get(); |
445 | template<typename T> struct B { |
446 | template<typename U> U *get(); |
447 | }; |
448 | }; |
449 | |
450 | template<typename T> void f(A a) { |
451 | a.get<A>()->get<T>(); |
452 | a.get<T>() |
453 | ->get<T>(); // expected-error {{use 'template'}} |
454 | a.get<T>()->template get<T>(); |
455 | a.A::get<T>(); |
456 | A::B<int> *b = a.get<A::B<int> >(); |
457 | b->get<int>(); |
458 | b->A::B<int>::get<int>(); |
459 | b->A::B<int>::get<T>(); |
460 | b->A::B<T>::get<int>(); // expected-error {{use 'template'}} |
461 | b->A::B<T>::template get<int>(); |
462 | b->A::B<T>::get<T>(); // expected-error {{use 'template'}} |
463 | b->A::B<T>::template get<T>(); |
464 | A::B<T> *c = a.get<A::B<T> >(); |
465 | c->get<int>(); // expected-error {{use 'template'}} |
466 | c->template get<int>(); |
467 | } |
468 | } |
469 | |
470 | namespace dr432 { // dr432: yes |
471 | template<typename T> struct A {}; |
472 | template<typename T> struct B : A<B> {}; // expected-error {{requires template arguments}} expected-note {{declared}} |
473 | template<typename T> struct C : A<C<T> > {}; |
474 | #if __cplusplus >= 201103L |
475 | template<typename T> struct D : decltype(A<D>()) {}; // expected-error {{requires template arguments}} expected-note {{declared}} |
476 | #endif |
477 | } |
478 | |
479 | namespace dr433 { // dr433: yes |
480 | template<class T> struct S { |
481 | void f(union U*); |
482 | }; |
483 | U *p; |
484 | template<class T> void S<T>::f(union U*) {} |
485 | |
486 | S<int> s; |
487 | } |
488 | |
489 | namespace dr434 { // dr434: yes |
490 | void f() { |
491 | const int ci = 0; |
492 | int *pi = 0; |
493 | const int *&rpci = pi; // expected-error {{cannot bind}} |
494 | rpci = &ci; |
495 | *pi = 1; |
496 | } |
497 | } |
498 | |
499 | // dr435: na |
500 | |
501 | namespace dr436 { // dr436: yes |
502 | enum E { f }; // expected-note {{previous}} |
503 | void f(); // expected-error {{redefinition}} |
504 | } |
505 | |
506 | namespace dr437 { // dr437: sup 1308 |
507 | // This is superseded by 1308, which is in turn superseded by 1330, |
508 | // which restores this rule. |
509 | template<typename U> struct T : U {}; |
510 | struct S { |
511 | void f() throw(S); |
512 | #if __cplusplus > 201402L |
513 | // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}} |
514 | #endif |
515 | void g() throw(T<S>); |
516 | #if __cplusplus > 201402L |
517 | // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}} |
518 | #endif |
519 | struct U; |
520 | void h() throw(U); |
521 | #if __cplusplus > 201402L |
522 | // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}} |
523 | #endif |
524 | struct U {}; |
525 | }; |
526 | } |
527 | |
528 | // dr438 FIXME write a codegen test |
529 | // dr439 FIXME write a codegen test |
530 | // dr441 FIXME write a codegen test |
531 | // dr442: sup 348 |
532 | // dr443: na |
533 | |
534 | namespace dr444 { // dr444: yes |
535 | struct D; |
536 | struct B { // expected-note {{candidate function (the implicit copy}} expected-note 0-1 {{implicit move}} |
537 | D &operator=(D &) = delete; // expected-error 0-1{{extension}} expected-note {{deleted}} |
538 | }; |
539 | struct D : B { // expected-note {{candidate function (the implicit copy}} expected-note 0-1 {{implicit move}} |
540 | using B::operator=; |
541 | } extern d; |
542 | void f() { |
543 | d = d; // expected-error {{deleted}} |
544 | } |
545 | } |
546 | |
547 | namespace dr445 { // dr445: yes |
548 | class A { void f(); }; // expected-note {{private}} |
549 | struct B { |
550 | friend void A::f(); // expected-error {{private}} |
551 | }; |
552 | } |
553 | |
554 | namespace dr446 { // dr446: yes |
555 | struct C; |
556 | struct A { |
557 | A(); |
558 | A(const A&) = delete; // expected-error 0-1{{extension}} expected-note +{{deleted}} |
559 | A(const C&); |
560 | }; |
561 | struct C : A {}; |
562 | void f(A a, bool b, C c) { |
563 | void(b ? a : a); |
564 | b ? A() : a; // expected-error {{deleted}} |
565 | b ? a : A(); // expected-error {{deleted}} |
566 | b ? A() : A(); |
567 | #if __cplusplus <= 201402L |
568 | // expected-error@-2 {{deleted}} |
569 | #endif |
570 | |
571 | void(b ? a : c); |
572 | b ? a : C(); // expected-error {{deleted}} |
573 | b ? c : A(); |
574 | #if __cplusplus <= 201402L |
575 | // expected-error@-2 {{deleted}} |
576 | #endif |
577 | b ? A() : C(); |
578 | #if __cplusplus <= 201402L |
579 | // expected-error@-2 {{deleted}} |
580 | #endif |
581 | } |
582 | } |
583 | |
584 | namespace dr447 { // dr447: yes |
585 | struct A { int n; int a[4]; }; |
586 | template<int> struct U { |
587 | typedef int type; |
588 | template<typename V> static void h(); |
589 | }; |
590 | template<typename T> U<sizeof(T)> g(T); |
591 | template<typename T, int N> void f(int n) { |
592 | // ok, not type dependent |
593 | g(__builtin_offsetof(A, n)).h<int>(); |
594 | g(__builtin_offsetof(T, n)).h<int>(); |
595 | // value dependent if first argument is a dependent type |
596 | U<__builtin_offsetof(A, n)>::type a; |
597 | U<__builtin_offsetof(T, n)>::type b; // expected-error +{{}} expected-warning 0+{{}} |
598 | // as an extension, we allow the member-designator to include array indices |
599 | g(__builtin_offsetof(A, a[0])).h<int>(); |
600 | g(__builtin_offsetof(A, a[N])).h<int>(); |
601 | U<__builtin_offsetof(A, a[0])>::type c; |
602 | U<__builtin_offsetof(A, a[N])>::type d; // expected-error +{{}} expected-warning 0+{{}} |
603 | } |
604 | } |
605 | |
606 | namespace dr448 { // dr448: yes |
607 | template<typename T = int> void f(int); // expected-error 0-1{{extension}} expected-note {{no known conversion}} |
608 | template<typename T> void g(T t) { |
609 | f<T>(t); // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}} |
610 | dr448::f(t); // expected-error {{no matching function}} |
611 | } |
612 | template<typename T> void f(T); // expected-note {{should be declared prior to the call site}} |
613 | namespace HideFromADL { struct X {}; } |
614 | template void g(int); // ok |
615 | template void g(HideFromADL::X); // expected-note {{instantiation of}} |
616 | } |
617 | |
618 | // dr449: na |
619 | |
620 | namespace dr450 { // dr450: yes |
621 | typedef int A[3]; |
622 | void f1(const A &); |
623 | void f2(A &); // expected-note +{{not viable}} |
624 | struct S { A n; }; |
625 | void g() { |
626 | f1(S().n); |
627 | f2(S().n); // expected-error {{no match}}} |
628 | } |
629 | #if __cplusplus >= 201103L |
630 | void h() { |
631 | f1(A{}); |
632 | f2(A{}); // expected-error {{no match}} |
633 | } |
634 | #endif |
635 | } |
636 | |
637 | namespace dr451 { // dr451: yes |
638 | const int a = 1 / 0; // expected-warning {{undefined}} |
639 | const int b = 1 / 0; // expected-warning {{undefined}} |
640 | int arr[b]; // expected-error +{{variable length arr}} |
641 | } |
642 | |
643 | namespace dr452 { // dr452: yes |
644 | struct A { |
645 | int a, b, c; |
646 | A *p; |
647 | int f(); |
648 | A() : a(f()), b(this->f() + a), c(this->a), p(this) {} |
649 | }; |
650 | } |
651 | |
652 | // dr454 FIXME write a codegen test |
653 | |
654 | namespace dr456 { // dr456: yes |
655 | // sup 903 c++11 |
656 | const int null = 0; |
657 | void *p = null; |
658 | #if __cplusplus >= 201103L |
659 | // expected-error@-2 {{cannot initialize}} |
660 | #else |
661 | // expected-warning@-4 {{null}} |
662 | #endif |
663 | |
664 | const bool f = false; |
665 | void *q = f; |
666 | #if __cplusplus >= 201103L |
667 | // expected-error@-2 {{cannot initialize}} |
668 | #else |
669 | // expected-warning@-4 {{null}} |
670 | #endif |
671 | } |
672 | |
673 | namespace dr457 { // dr457: yes |
674 | const int a = 1; |
675 | const volatile int b = 1; |
676 | int ax[a]; |
677 | int bx[b]; // expected-error +{{variable length array}} |
678 | |
679 | enum E { |
680 | ea = a, |
681 | eb = b // expected-error {{constant}} expected-note {{read of volatile-qualified}} |
682 | }; |
683 | } |
684 | |
685 | namespace dr458 { // dr458: no |
686 | struct A { |
687 | int T; |
688 | int f(); |
689 | template<typename> int g(); |
690 | }; |
691 | |
692 | template<typename> struct B : A { |
693 | int f(); |
694 | template<typename> int g(); |
695 | template<typename> int h(); |
696 | }; |
697 | |
698 | int A::f() { |
699 | return T; |
700 | } |
701 | template<typename T> |
702 | int A::g() { |
703 | return T; // FIXME: this is invalid, it finds the template parameter |
704 | } |
705 | |
706 | template<typename T> |
707 | int B<T>::f() { |
708 | return T; |
709 | } |
710 | template<typename T> template<typename U> |
711 | int B<T>::g() { |
712 | return T; |
713 | } |
714 | template<typename U> template<typename T> |
715 | int B<U>::h() { |
716 | return T; // FIXME: this is invalid, it finds the template parameter |
717 | } |
718 | } |
719 | |
720 | namespace dr460 { // dr460: yes |
721 | namespace X { namespace Q { int n; } } |
722 | namespace Y { |
723 | using X; // expected-error {{requires a qualified name}} |
724 | using dr460::X; // expected-error {{cannot refer to a namespace}} |
725 | using X::Q; // expected-error {{cannot refer to a namespace}} |
726 | } |
727 | } |
728 | |
729 | // dr461: na |
730 | // dr462 FIXME write a codegen test |
731 | // dr463: na |
732 | // dr464: na |
733 | // dr465: na |
734 | |
735 | namespace dr466 { // dr466: no |
736 | typedef int I; |
737 | typedef const int CI; |
738 | typedef volatile int VI; |
739 | void f(int *a, CI *b, VI *c) { |
740 | a->~I(); |
741 | a->~CI(); |
742 | a->~VI(); |
743 | a->I::~I(); |
744 | a->CI::~CI(); |
745 | a->VI::~VI(); |
746 | |
747 | a->CI::~VI(); // FIXME: This is invalid; CI and VI are not the same scalar type. |
748 | |
749 | b->~I(); |
750 | b->~CI(); |
751 | b->~VI(); |
752 | b->I::~I(); |
753 | b->CI::~CI(); |
754 | b->VI::~VI(); |
755 | |
756 | c->~I(); |
757 | c->~CI(); |
758 | c->~VI(); |
759 | c->I::~I(); |
760 | c->CI::~CI(); |
761 | c->VI::~VI(); |
762 | } |
763 | } |
764 | |
765 | namespace dr467 { // dr467: yes |
766 | int stuff(); |
767 | |
768 | int f() { |
769 | static bool done; |
770 | if (done) |
771 | goto later; |
772 | static int k = stuff(); |
773 | done = true; |
774 | later: |
775 | return k; |
776 | } |
777 | int g() { |
778 | goto later; // expected-error {{cannot jump}} |
779 | int k = stuff(); // expected-note {{bypasses variable initialization}} |
780 | later: |
781 | return k; |
782 | } |
783 | } |
784 | |
785 | namespace dr468 { // dr468: yes c++11 |
786 | // FIXME: Should we allow this in C++98 too? |
787 | template<typename> struct A { |
788 | template<typename> struct B { |
789 | static int C; |
790 | }; |
791 | }; |
792 | int k = dr468::template A<int>::template B<char>::C; |
793 | #if __cplusplus < 201103L |
794 | // expected-error@-2 2{{'template' keyword outside of a template}} |
795 | #endif |
796 | } |
797 | |
798 | namespace dr469 { // dr469: no |
799 | template<typename T> struct X; // expected-note {{here}} |
800 | template<typename T> struct X<const T> {}; |
801 | X<int&> x; // expected-error {{undefined}} |
802 | } |
803 | |
804 | namespace dr470 { // dr470: yes |
805 | template<typename T> struct A { |
806 | struct B {}; |
807 | }; |
808 | template<typename T> struct C { |
809 | }; |
810 | |
811 | template struct A<int>; // expected-note {{previous}} |
812 | template struct A<int>::B; // expected-error {{duplicate explicit instantiation}} |
813 | |
814 | // ok, instantiating C<char> doesn't instantiate base class members. |
815 | template struct A<char>; |
816 | template struct C<char>; |
817 | } |
818 | |
819 | namespace dr471 { // dr471: yes |
820 | struct A { int n; }; |
821 | struct B : private virtual A {}; |
822 | struct C : protected virtual A {}; |
823 | struct D : B, C { int f() { return n; } }; |
824 | struct E : private virtual A { |
825 | using A::n; |
826 | }; |
827 | struct F : E, B { int f() { return n; } }; |
828 | struct G : virtual A { |
829 | private: |
830 | using A::n; // expected-note {{here}} |
831 | }; |
832 | struct H : B, G { int f() { return n; } }; // expected-error {{private}} |
833 | } |
834 | |
835 | namespace dr474 { // dr474: yes |
836 | namespace N { |
837 | struct S { |
838 | void f(); |
839 | }; |
840 | } |
841 | void N::S::f() { |
842 | void g(); // expected-note {{previous}} |
843 | } |
844 | int g(); |
845 | namespace N { |
846 | int g(); // expected-error {{cannot be overloaded}} |
847 | } |
848 | } |
849 | |
850 | // dr475 FIXME write a codegen test |
851 | |
852 | namespace dr477 { // dr477: 3.5 |
853 | struct A { |
854 | explicit A(); |
855 | virtual void f(); |
856 | }; |
857 | struct B { |
858 | friend explicit A::A(); // expected-error {{'explicit' is invalid in friend declarations}} |
859 | friend virtual void A::f(); // expected-error {{'virtual' is invalid in friend declarations}} |
860 | }; |
861 | explicit A::A() {} // expected-error {{can only be specified inside the class definition}} |
862 | virtual void A::f() {} // expected-error {{can only be specified inside the class definition}} |
863 | } |
864 | |
865 | namespace dr478 { // dr478: yes |
866 | struct A { virtual void f() = 0; }; // expected-note {{unimplemented}} |
867 | void f(A *a); |
868 | void f(A a[10]); // expected-error {{array of abstract class type}} |
869 | } |
870 | |
871 | namespace dr479 { // dr479: yes |
872 | struct S { |
873 | S(); |
874 | private: |
875 | S(const S&); // expected-note +{{here}} |
876 | ~S(); // expected-note +{{here}} |
877 | }; |
878 | void f() { |
879 | throw S(); |
880 | // expected-error@-1 {{temporary of type 'dr479::S' has private destructor}} |
881 | // expected-error@-2 {{exception object of type 'dr479::S' has private destructor}} |
882 | #if __cplusplus < 201103L |
883 | // expected-error@-4 {{C++98 requires an accessible copy constructor}} |
884 | #endif |
885 | #if __cplusplus <= 201402L |
886 | // expected-error@-7 {{calling a private constructor}} (copy ctor) |
887 | #endif |
888 | } |
889 | void g() { |
890 | S s; // expected-error {{private destructor}}} |
891 | throw s; |
892 | // expected-error@-1 {{calling a private constructor}} |
893 | // expected-error@-2 {{exception object of type 'dr479::S' has private destructor}} |
894 | } |
895 | void h() { |
896 | try { |
897 | f(); |
898 | g(); |
899 | } catch (S s) { |
900 | // expected-error@-1 {{calling a private constructor}} |
901 | // expected-error@-2 {{variable of type 'dr479::S' has private destructor}} |
902 | } |
903 | } |
904 | } |
905 | |
906 | namespace dr480 { // dr480: yes |
907 | struct A { int n; }; |
908 | struct B : A {}; |
909 | struct C : virtual B {}; |
910 | struct D : C {}; |
911 | |
912 | int A::*a = &A::n; |
913 | int D::*b = a; // expected-error {{virtual base}} |
914 | |
915 | extern int D::*c; |
916 | int A::*d = static_cast<int A::*>(c); // expected-error {{virtual base}} |
917 | |
918 | D *e; |
919 | A *f = e; |
920 | D *g = static_cast<D*>(f); // expected-error {{virtual base}} |
921 | |
922 | extern D &i; |
923 | A &j = i; |
924 | D &k = static_cast<D&>(j); // expected-error {{virtual base}} |
925 | } |
926 | |
927 | namespace dr481 { // dr481: yes |
928 | template<class T, T U> class A { T *x; }; |
929 | T *x; // expected-error {{unknown type}} |
930 | |
931 | template<class T *U> class B { T *x; }; |
932 | T *y; // ok |
933 | |
934 | struct C { |
935 | template<class T> void f(class D *p); |
936 | }; |
937 | D *z; // ok |
938 | |
939 | template<typename A = C, typename C = A> struct E { |
940 | void f() { |
941 | typedef ::dr481::C c; // expected-note {{previous}} |
942 | typedef C c; // expected-error {{different type}} |
943 | } |
944 | }; |
945 | template struct E<>; // ok |
946 | template struct E<int>; // expected-note {{instantiation of}} |
947 | |
948 | template<template<typename U_no_typo_correction> class A, |
949 | A<int> *B, |
950 | U_no_typo_correction *C> // expected-error {{unknown type}} |
951 | struct F { |
952 | U_no_typo_correction *x; // expected-error {{unknown type}} |
953 | }; |
954 | |
955 | template<template<class H *> class> struct G { |
956 | H *x; |
957 | }; |
958 | H *q; |
959 | |
960 | typedef int N; |
961 | template<N X, typename N, template<N Y> class T> struct I; |
962 | template<char*> struct J; |
963 | I<123, char*, J> *j; |
964 | } |
965 | |
966 | namespace dr482 { // dr482: 3.5 |
967 | extern int a; |
968 | void f(); |
969 | |
970 | int dr482::a = 0; // expected-warning {{extra qualification}} |
971 | void dr482::f() {} // expected-warning {{extra qualification}} |
972 | |
973 | inline namespace X { // expected-error 0-1{{C++11 feature}} |
974 | extern int b; |
975 | void g(); |
976 | struct S; |
977 | } |
978 | int dr482::b = 0; // expected-warning {{extra qualification}} |
979 | void dr482::g() {} // expected-warning {{extra qualification}} |
980 | struct dr482::S {}; // expected-warning {{extra qualification}} |
981 | |
982 | void dr482::f(); // expected-warning {{extra qualification}} |
983 | void dr482::g(); // expected-warning {{extra qualification}} |
984 | |
985 | // FIXME: The following are valid in DR482's wording, but these are bugs in |
986 | // the wording which we deliberately don't implement. |
987 | namespace N { typedef int type; } |
988 | typedef int N::type; // expected-error {{typedef declarator cannot be qualified}} |
989 | struct A { |
990 | struct B; |
991 | struct A::B {}; // expected-error {{extra qualification}} |
992 | |
993 | #if __cplusplus >= 201103L |
994 | enum class C; |
995 | enum class A::C {}; // expected-error {{extra qualification}} |
996 | #endif |
997 | }; |
998 | } |
999 | |
1000 | namespace dr483 { // dr483: yes |
1001 | namespace climits { |
1002 | int check1[__SCHAR_MAX__ >= 127 ? 1 : -1]; |
1003 | int check2[__SHRT_MAX__ >= 32767 ? 1 : -1]; |
1004 | int check3[__INT_MAX__ >= 32767 ? 1 : -1]; |
1005 | int check4[__LONG_MAX__ >= 2147483647 ? 1 : -1]; |
1006 | int check5[__LONG_LONG_MAX__ >= 9223372036854775807 ? 1 : -1]; |
1007 | #if __cplusplus < 201103L |
1008 | // expected-error@-2 {{extension}} |
1009 | #endif |
1010 | } |
1011 | namespace cstdint { |
1012 | int check1[__PTRDIFF_WIDTH__ >= 16 ? 1 : -1]; |
1013 | int check2[__SIG_ATOMIC_WIDTH__ >= 8 ? 1 : -1]; |
1014 | int check3[__SIZE_WIDTH__ >= 16 ? 1 : -1]; |
1015 | int check4[__WCHAR_WIDTH__ >= 8 ? 1 : -1]; |
1016 | int check5[__WINT_WIDTH__ >= 16 ? 1 : -1]; |
1017 | } |
1018 | } |
1019 | |
1020 | namespace dr484 { // dr484: yes |
1021 | struct A { |
1022 | A(); |
1023 | void f(); |
1024 | }; |
1025 | typedef const A CA; |
1026 | void CA::f() { |
1027 | this->~CA(); |
1028 | this->CA::~A(); |
1029 | this->CA::A::~A(); |
1030 | } |
1031 | CA::A() {} |
1032 | |
1033 | struct B : CA { |
1034 | B() : CA() {} |
1035 | void f() { return CA::f(); } |
1036 | }; |
1037 | |
1038 | struct C; |
1039 | typedef C CT; // expected-note {{here}} |
1040 | struct CT {}; // expected-error {{conflicts with typedef}} |
1041 | |
1042 | namespace N { |
1043 | struct D; |
1044 | typedef D DT; // expected-note {{here}} |
1045 | } |
1046 | struct N::DT {}; // expected-error {{conflicts with typedef}} |
1047 | |
1048 | typedef struct { |
1049 | S(); // expected-error {{requires a type}} |
1050 | } S; |
1051 | } |
1052 | |
1053 | namespace dr485 { // dr485: yes |
1054 | namespace N { |
1055 | struct S {}; |
1056 | int operator+(S, S); |
1057 | template<typename T> int f(S); |
1058 | } |
1059 | template<typename T> int f(); |
1060 | |
1061 | N::S s; |
1062 | int a = operator+(s, s); |
1063 | int b = f<int>(s); |
1064 | } |
1065 | |
1066 | namespace dr486 { // dr486: yes |
1067 | template<typename T> T f(T *); // expected-note 2{{substitution failure}} |
1068 | int &f(...); |
1069 | |
1070 | void g(); |
1071 | int n[10]; |
1072 | |
1073 | void h() { |
1074 | int &a = f(&g); |
1075 | int &b = f(&n); |
1076 | f<void()>(&g); // expected-error {{no match}} |
1077 | f<int[10]>(&n); // expected-error {{no match}} |
1078 | } |
1079 | } |
1080 | |
1081 | namespace dr487 { // dr487: yes |
1082 | enum E { e }; |
1083 | int operator+(int, E); |
1084 | int i[4 + e]; // expected-error 2{{variable length array}} |
1085 | } |
1086 | |
1087 | namespace dr488 { // dr488: yes c++11 |
1088 | template <typename T> void f(T); |
1089 | void f(int); |
1090 | void g() { |
1091 | // FIXME: It seems CWG thought this should be a SFINAE failure prior to |
1092 | // allowing local types as template arguments. In C++98, we should either |
1093 | // allow local types as template arguments or treat this as a SFINAE |
1094 | // failure. |
1095 | enum E { e }; |
1096 | f(e); |
1097 | #if __cplusplus < 201103L |
1098 | // expected-error@-2 {{local type}} |
1099 | #endif |
1100 | } |
1101 | } |
1102 | |
1103 | // dr489: na |
1104 | |
1105 | namespace dr490 { // dr490: yes |
1106 | template<typename T> struct X {}; |
1107 | |
1108 | struct A { |
1109 | typedef int T; |
1110 | struct K {}; // expected-note {{declared}} |
1111 | |
1112 | int f(T); |
1113 | int g(T); |
1114 | int h(X<T>); |
1115 | int X<T>::*i(); // expected-note {{previous}} |
1116 | int K::*j(); |
1117 | |
1118 | template<typename T> T k(); |
1119 | |
1120 | operator X<T>(); |
1121 | }; |
1122 | |
1123 | struct B { |
1124 | typedef char T; |
1125 | typedef int U; |
1126 | friend int A::f(T); |
1127 | friend int A::g(U); |
1128 | friend int A::h(X<T>); |
1129 | |
1130 | // FIXME: Per this DR, these two are valid! That is another defect |
1131 | // (no number yet...) which will eventually supersede this one. |
1132 | friend int X<T>::*A::i(); // expected-error {{return type}} |
1133 | friend int K::*A::j(); // expected-error {{undeclared identifier 'K'; did you mean 'A::K'?}} |
1134 | |
1135 | // ok, lookup finds B::T, not A::T, so return type matches |
1136 | friend char A::k<T>(); |
1137 | friend int A::k<U>(); |
1138 | |
1139 | // A conversion-type-id in a conversion-function-id is always looked up in |
1140 | // the class of the conversion function first. |
1141 | friend A::operator X<T>(); |
1142 | }; |
1143 | } |
1144 | |
1145 | namespace dr491 { // dr491: dup 413 |
1146 | struct A {} a, b[3] = { a, {} }; |
1147 | A c[2] = { a, {}, b[1] }; // expected-error {{excess elements}} |
1148 | } |
1149 | |
1150 | // dr492 FIXME write a codegen test |
1151 | |
1152 | namespace dr493 { // dr493: dup 976 |
1153 | struct X { |
1154 | template <class T> operator const T &() const; |
1155 | }; |
1156 | void f() { |
1157 | if (X()) { |
1158 | } |
1159 | } |
1160 | } |
1161 | |
1162 | namespace dr494 { // dr494: dup 372 |
1163 | class A { |
1164 | class B {}; |
1165 | friend class C; |
1166 | }; |
1167 | class C : A::B { |
1168 | A::B x; |
1169 | class D : A::B { |
1170 | A::B y; |
1171 | }; |
1172 | }; |
1173 | } |
1174 | |
1175 | namespace dr495 { // dr495: 3.5 |
1176 | template<typename T> |
1177 | struct S { |
1178 | operator int() { return T::error; } |
1179 | template<typename U> operator U(); |
1180 | }; |
1181 | S<int> s; |
1182 | long n = s; |
1183 | |
1184 | template<typename T> |
1185 | struct S2 { |
1186 | template<typename U> operator U(); |
1187 | operator int() { return T::error; } |
1188 | }; |
1189 | S2<int> s2; |
1190 | long n2 = s2; |
1191 | } |
1192 | |
1193 | namespace dr496 { // dr496: sup 2094 |
1194 | struct A { int n; }; |
1195 | struct B { volatile int n; }; |
1196 | int check1[ __is_trivially_copyable(const int) ? 1 : -1]; |
1197 | // This checks the dr2094 behavior, not dr496 |
1198 | int check2[ __is_trivially_copyable(volatile int) ? 1 : -1]; |
1199 | int check3[ __is_trivially_constructible(A, const A&) ? 1 : -1]; |
1200 | int check4[ __is_trivially_constructible(B, const B&) ? 1 : -1]; |
1201 | int check5[ __is_trivially_assignable(A, const A&) ? 1 : -1]; |
1202 | int check6[ __is_trivially_assignable(B, const B&) ? 1 : -1]; |
1203 | } |
1204 | |
1205 | namespace dr497 { // dr497: sup 253 |
1206 | void before() { |
1207 | struct S { |
1208 | mutable int i; |
1209 | }; |
1210 | const S cs; |
1211 | int S::*pm = &S::i; |
1212 | cs.*pm = 88; // expected-error {{not assignable}} |
1213 | } |
1214 | |
1215 | void after() { |
1216 | struct S { |
1217 | S() : i(0) {} |
1218 | mutable int i; |
1219 | }; |
1220 | const S cs; |
1221 | int S::*pm = &S::i; |
1222 | cs.*pm = 88; // expected-error {{not assignable}} |
1223 | } |
1224 | } |
1225 | |
1226 | namespace dr499 { // dr499: yes |
1227 | extern char str[]; |
1228 | void f() { throw str; } |
1229 | } |
1230 | |