1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5
6 // FIXME: This is included to avoid a diagnostic with no source location
7 // pointing at the implicit operator new. We can't match such a diagnostic
8 // with -verify.
9 __extension__ typedef __SIZE_TYPE__ size_t;
10 void *operator new(size_t); // expected-warning 0-1{{missing exception spec}} expected-note{{candidate}}
11
12 namespace dr500 { // dr500: dup 372
13 class D;
14 class A {
15 class B;
16 class C;
17 friend class D;
18 };
19 class A::B {};
20 class A::C : public A::B {};
21 class D : public A::B {};
22 }
23
24 namespace dr501 { // dr501: yes
25 struct A {
f()26 friend void f() {}
gdr501::A27 void g() {
28 void (*p)() = &f; // expected-error {{undeclared identifier}}
29 }
30 };
31 }
32
33 namespace dr502 { // dr502: yes
34 struct Q {};
35 template<typename T> struct A {
36 enum E { e = 1 };
q1dr502::A37 void q1() { f(e); }
q2dr502::A38 void q2() { Q arr[sizeof(E)]; f(arr); }
q3dr502::A39 void q3() { Q arr[e]; f(arr); }
sanitydr502::A40 void sanity() { Q arr[1]; f(arr); } // expected-error {{undeclared identifier 'f'}}
41 };
42 int f(A<int>::E);
43 template<int N> int f(Q (&)[N]);
44 template struct A<int>;
45 }
46
47 namespace dr505 { // dr505: yes
48 const char *exts = "\e\(\{\[\%"; // expected-error 5{{use of non-standard escape}}
49 const char *unknown = "\Q"; // expected-error {{unknown escape sequence}}
50 }
51
52 namespace dr506 { // dr506: yes
53 struct NonPod { ~NonPod(); };
54 void f(...);
g(NonPod np)55 void g(NonPod np) { f(np); } // expected-error {{cannot pass}}
56 }
57
58 // FIXME: Add tests here once DR260 is resolved.
59 // dr507: dup 260
60
61 // dr508: na
62 // dr509: na
63 // dr510: na
64
65 namespace dr512 { // dr512: yes
66 struct A {
67 A(int);
68 };
69 union U { A a; };
70 #if __cplusplus < 201103L
71 // expected-error@-2 {{has a non-trivial constructor}}
72 // expected-note@-6 {{no default constructor}}
73 // expected-note@-6 {{suppressed by user-declared constructor}}
74 #endif
75 }
76
77 // dr513: na
78
79 namespace dr514 { // dr514: yes
80 namespace A { extern int x, y; }
81 int A::x = y;
82 }
83
84 namespace dr515 { // dr515: sup 1017
85 // FIXME: dr1017 reverses the wording of dr515, but the current draft has
86 // dr515's wording, with a different fix for dr1017.
87
88 struct X { int n; };
89 template<typename T> struct Y : T {
fdr515::Y90 int f() { return X::n; }
91 };
92 int k = Y<X>().f();
93
94 struct A { int a; };
fdr515::B95 struct B { void f() { int k = sizeof(A::a); } };
96 #if __cplusplus < 201103L
97 // expected-error@-2 {{invalid use of non-static data member}}
98 #endif
99 }
100
101 // dr516: na
102
103 namespace dr517 { // dr517: no
104 // This is NDR, but we should diagnose it anyway.
105 template<typename T> struct S {};
106 template<typename T> int v = 0; // expected-error 0-1{{extension}}
107
108 template struct S<int*>;
109 template int v<int*>;
110
111 S<char&> s;
112 int k = v<char&>;
113
114 // FIXME: These are both ill-formed.
115 template<typename T> struct S<T*> {};
116 template<typename T> int v<T*> = 0; // expected-error 0-1{{extension}}
117
118 // FIXME: These are both ill-formed.
119 template<typename T> struct S<T&> {};
120 template<typename T> int v<T&> = 0; // expected-error 0-1{{extension}}
121 }
122
123 namespace dr518 { // dr518: yes c++11
124 enum E { e, };
125 #if __cplusplus < 201103L
126 // expected-error@-2 {{C++11 extension}}
127 #endif
128 }
129
130 namespace dr519 { // dr519: yes
131 // FIXME: Add a codegen test.
132 #if __cplusplus >= 201103L
133 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
134 int test[fold((int*)(void*)0) ? -1 : 1];
135 #undef fold
136 #endif
137 }
138
139 // dr520: na
140
141 // dr521: no
142 // FIXME: The wording here is broken. It's not reasonable to expect a
143 // diagnostic here. Once the relevant DR gets a number, mark this as a dup.
144
145 namespace dr522 { // dr522: yes
146 struct S {};
147 template<typename T> void b1(volatile T &);
148 template<typename T> void b2(volatile T * const *);
149 template<typename T> void b2(volatile T * const S::*);
150 template<typename T> void b2(volatile T * const S::* const *);
151 // FIXME: This diagnostic isn't very good. The problem is not substitution failure.
152 template<typename T> void b2a(volatile T *S::* const *); // expected-note {{substitution failure}}
153
154 template<typename T> struct Base {};
155 struct Derived : Base<int> {};
156 template<typename T> void b3(Base<T>);
157 template<typename T> void b3(Base<T> *);
158
test(int n,const int cn,int ** p,int * S::* pm)159 void test(int n, const int cn, int **p, int *S::*pm) {
160 int *a[3], *S::*am[3];
161 const Derived cd = Derived();
162 Derived d[3];
163
164 b1(n);
165 b1(cn);
166 b2(p);
167 b2(pm);
168 b2(a);
169 b2(am);
170 b2a(am); // expected-error {{no matching function}}
171 b3(d);
172 b3(cd);
173 }
174 }
175
176 namespace dr524 { // dr524: yes
f(T a,T b)177 template<typename T> void f(T a, T b) { operator+(a, b); } // expected-error {{call}}
178
179 struct S {};
180 void operator+(S, S);
181 template void f(S, S);
182
183 namespace N { struct S {}; }
184 void operator+(N::S, N::S); // expected-note {{should be declared}}
185 template void f(N::S, N::S); // expected-note {{instantiation}}
186 }
187
188 namespace dr525 { // dr525: yes
189 namespace before {
190 // Note, the example was correct prior to the change; instantiation is
191 // required for cases like this:
192 template <class T> struct D { operator T*(); };
g(D<double> ppp)193 void g(D<double> ppp) {
194 delete ppp;
195 }
196 }
197 namespace after {
198 template <class T> struct D { typename T::error e; }; // expected-error {{prior to '::'}}
g(D<double> * ppp)199 void g(D<double> *ppp) {
200 delete ppp; // expected-note {{instantiation of}}
201 }
202 }
203 }
204
205 namespace dr526 { // dr526: yes
206 template<int> struct S {};
207 template<int N> void f1(S<N> s);
208 template<int N> void f2(S<(N)> s); // expected-note {{couldn't infer}}
209 template<int N> void f3(S<+N> s); // expected-note {{couldn't infer}}
210 template<int N> void g1(int (&)[N]);
211 template<int N> void g2(int (&)[(N)]); // expected-note {{couldn't infer}}
212 template<int N> void g3(int (&)[+N]); // expected-note {{couldn't infer}}
213
test(int (& a)[3],S<3> s)214 void test(int (&a)[3], S<3> s) {
215 f1(s);
216 f2(s); // expected-error {{no matching}}
217 f3(s); // expected-error {{no matching}}
218 g1(a);
219 g2(a); // expected-error {{no matching}}
220 g3(a); // expected-error {{no matching}}
221 }
222
223 template<int N> struct X {
224 typedef int type;
225 X<N>::type v1;
226 X<(N)>::type v2; // expected-error {{missing 'typename'}}
227 X<+N>::type v3; // expected-error {{missing 'typename'}}
228 };
229 }
230
231 namespace dr527 { // dr527: na
232 // This DR is meaningless. It removes a required diagnostic from the case
233 // where a not-externally-visible object is odr-used but not defined, which
234 // requires a diagnostic for a different reason.
235 extern struct { int x; } a; // FIXME: We should reject this, per dr389.
236 static struct { int x; } b;
237 extern "C" struct { int x; } c;
238 namespace { extern struct { int x; } d; }
239 typedef struct { int x; } *P;
240 struct E { static P e; }; // FIXME: We should reject this, per dr389.
241 namespace { struct F { static P f; }; }
242
243 int ax = a.x, bx = b.x, cx = c.x, dx = d.x, ex = E::e->x, fx = F::f->x;
244 }
245
246 namespace dr530 { // dr530: yes
247 template<int*> struct S { enum { N = 1 }; };
248 template<void(*)()> struct T { enum { N = 1 }; };
249 int n;
250 void f();
251 int a[S<&n>::N];
252 int b[T<&f>::N];
253 }
254
255 namespace dr531 { // dr531: partial
256 namespace good {
257 template<typename T> struct A {
fdr531::good::A258 void f(T) { T::error; }
gdr531::good::A259 template<typename U> void g(T, U) { T::error; }
260 struct B { typename T::error error; };
261 template<typename U> struct C { typename T::error error; };
262 static T n;
263 };
264 template<typename T> T A<T>::n = T::error;
265
f(int)266 template<> void A<int>::f(int) {}
g(int,U)267 template<> template<typename U> void A<int>::g(int, U) {}
268 template<> struct A<int>::B {};
269 template<> template<typename U> struct A<int>::C {};
270 template<> int A<int>::n = 0;
271
use(A<int> a)272 void use(A<int> a) {
273 a.f(a.n);
274 a.g(0, 0);
275 A<int>::B b;
276 A<int>::C<int> c;
277 }
278
279 template<> struct A<char> {
280 void f(char);
281 template<typename U> void g(char, U);
282 struct B;
283 template<typename U> struct C;
284 static char n;
285 };
286
f(char)287 void A<char>::f(char) {}
g(char,U)288 template<typename U> void A<char>::g(char, U) {}
289 struct A<char>::B {};
290 template<typename U> struct A<char>::C {};
291 char A<char>::n = 0;
292 }
293
294 namespace bad {
295 template<typename T> struct A {
fdr531::bad::A296 void f(T) { T::error; }
gdr531::bad::A297 template<typename U> void g(T, U) { T::error; }
298 struct B { typename T::error error; };
299 template<typename U> struct C { typename T::error error; }; // expected-note {{here}}
300 static T n;
301 };
302 template<typename T> T A<T>::n = T::error;
303
f(int)304 void A<int>::f(int) {} // expected-error {{requires 'template<>'}}
g(int,U)305 template<typename U> void A<int>::g(int, U) {} // expected-error {{should be empty}}
306 struct A<int>::B {}; // expected-error {{requires 'template<>'}}
307 template<typename U> struct A<int>::C {}; // expected-error {{should be empty}} expected-error {{different kind of symbol}}
308 int A<int>::n = 0; // expected-error {{requires 'template<>'}}
309
310 template<> struct A<char> { // expected-note 2{{here}}
311 void f(char);
312 template<typename U> void g(char, U);
313 struct B; // expected-note {{here}}
314 template<typename U> struct C;
315 static char n;
316 };
317
f(char)318 template<> void A<char>::f(char) {} // expected-error {{no function template matches}}
319 // FIXME: This is ill-formed; -pedantic-errors should reject.
g(char,U)320 template<> template<typename U> void A<char>::g(char, U) {} // expected-warning {{extraneous template parameter list}}
321 template<> struct A<char>::B {}; // expected-error {{extraneous 'template<>'}} expected-error {{does not specialize}}
322 // FIXME: This is ill-formed; -pedantic-errors should reject.
323 template<> template<typename U> struct A<char>::C {}; // expected-warning {{extraneous template parameter list}}
324 template<> char A<char>::n = 0; // expected-error {{extraneous 'template<>'}}
325 }
326
327 namespace nested {
328 template<typename T> struct A {
329 template<typename U> struct B;
330 };
331 template<> template<typename U> struct A<int>::B {
332 void f();
333 void g();
334 template<typename V> void h();
335 template<typename V> void i();
336 };
f()337 template<> template<typename U> void A<int>::B<U>::f() {}
g()338 template<typename U> void A<int>::B<U>::g() {} // expected-error {{should be empty}}
339
h()340 template<> template<typename U> template<typename V> void A<int>::B<U>::h() {}
i()341 template<typename U> template<typename V> void A<int>::B<U>::i() {} // expected-error {{should be empty}}
342
f()343 template<> template<> void A<int>::B<int>::f() {}
h()344 template<> template<> template<typename V> void A<int>::B<int>::h() {}
h()345 template<> template<> template<> void A<int>::B<int>::h<int>() {}
346
f()347 template<> void A<int>::B<char>::f() {} // expected-error {{requires 'template<>'}}
h()348 template<> template<typename V> void A<int>::B<char>::h() {} // expected-error {{should be empty}}
349 }
350 }
351
352 // PR8130
353 namespace dr532 { // dr532: 3.5
354 struct A { };
355
356 template<class T> struct B {
357 template<class R> int &operator*(R&);
358 };
359
360 template<class T, class R> float &operator*(T&, R&);
test()361 void test() {
362 A a;
363 B<A> b;
364 int &ir = b * a;
365 }
366 }
367
368 // dr533: na
369
370 namespace dr534 { // dr534: yes
371 struct S {};
372 template<typename T> void operator+(S, T);
373 template<typename T> void operator+<T*>(S, T*) {} // expected-error {{function template partial spec}}
374 }
375
376 namespace dr535 { // dr535: yes
377 class X { private: X(const X&); };
378 struct A {
379 X x;
380 template<typename T> A(T&);
381 };
382 struct B : A {
383 X y;
384 B(volatile A&);
385 };
386
387 extern A a1;
388 A a2(a1); // ok, uses constructor template
389
390 extern volatile B b1;
391 B b2(b1); // ok, uses converting constructor
392
f()393 void f() { throw a1; }
394
395 #if __cplusplus >= 201103L
396 struct C {
Cdr535::C397 constexpr C() : n(0) {}
Cdr535::C398 template<typename T> constexpr C(T&t) : n(t.n == 0 ? throw 0 : 0) {}
399 int n;
400 };
c()401 constexpr C c() { return C(); }
402 // ok, copy is elided
403 constexpr C x = c();
404 #endif
405 }
406
407 // dr537: na
408 // dr538: na
409
410 // dr539: yes
dr539(const a)411 const dr539( // expected-error {{requires a type specifier}}
412 const a) { // expected-error {{unknown type name 'a'}}
413 const b; // expected-error {{requires a type specifier}}
414 new const; // expected-error {{expected a type}}
415 try {} catch (const n) {} // expected-error {{unknown type name 'n'}}
416 try {} catch (const) {} // expected-error {{expected a type}}
417 if (const n = 0) {} // expected-error {{requires a type specifier}}
418 switch (const n = 0) {} // expected-error {{requires a type specifier}}
419 while (const n = 0) {} // expected-error {{requires a type specifier}}
420 for (const n = 0; // expected-error {{requires a type specifier}}
421 const m = 0; ) {} // expected-error {{requires a type specifier}}
422 sizeof(const); // expected-error {{requires a type specifier}}
423 struct S {
424 const n; // expected-error {{requires a type specifier}}
425 operator const(); // expected-error {{expected a type}}
426 };
427 #if __cplusplus >= 201103L
428 int arr[3];
429 // FIXME: The extra braces here are to avoid the parser getting too
430 // badly confused when recovering here. We should fix this recovery.
431 { for (const n // expected-error {{unknown type name 'n'}} expected-note {{}}
432 : arr) ; {} } // expected-error +{{}}
433 (void) [](const) {}; // expected-error {{requires a type specifier}}
434 (void) [](const n) {}; // expected-error {{unknown type name 'n'}}
435 enum E : const {}; // expected-error {{expected a type}}
436 using T = const; // expected-error {{expected a type}}
437 auto f() -> const; // expected-error {{expected a type}}
438 #endif
439 }
440
441 namespace dr540 { // dr540: yes
442 typedef int &a;
443 typedef const a &a; // expected-warning {{has no effect}}
444 typedef const int &b;
445 typedef b &b;
446 typedef const a &c; // expected-note {{previous}} expected-warning {{has no effect}}
447 typedef const b &c; // expected-error {{different}} expected-warning {{has no effect}}
448 }
449
450 namespace dr541 { // dr541: yes
451 template<int> struct X { typedef int type; };
452 template<typename T> struct S {
453 int f(T);
454
455 int g(int);
456 T g(bool);
457
458 int h();
459 int h(T);
460
xdr541::S461 void x() {
462 // These are type-dependent expressions, even though we could
463 // determine that all calls have type 'int'.
464 X<sizeof(f(0))>::type a; // expected-error +{{}}
465 X<sizeof(g(0))>::type b; // expected-error +{{}}
466 X<sizeof(h(0))>::type b; // expected-error +{{}}
467
468 typename X<sizeof(f(0))>::type a;
469 typename X<sizeof(h(0))>::type b;
470 }
471 };
472 }
473
474 namespace dr542 { // dr542: yes
475 #if __cplusplus >= 201103L
476 struct A { A() = delete; int n; };
477 A a[32] = {}; // ok, constructor not called
478
479 struct B {
480 int n;
481 private:
482 B() = default;
483 };
484 B b[32] = {}; // ok, constructor not called
485 #endif
486 }
487
488 namespace dr543 { // dr543: yes
489 // In C++98+DR543, this is valid because value-initialization doesn't call a
490 // trivial default constructor, so we never notice that defining the
491 // constructor would be ill-formed.
492 //
493 // In C++11+DR543, this is ill-formed, because the default constructor is
494 // deleted, and value-initialization *does* call a deleted default
495 // constructor, even if it is trivial.
496 struct A {
497 const int n;
498 };
499 A a = A();
500 #if __cplusplus >= 201103L
501 // expected-error@-2 {{deleted}}
502 // expected-note@-5 {{would not be initialized}}
503 #endif
504 }
505
506 namespace dr544 { // dr544: yes
507 int *n;
508
509 template<class T> struct A { int n; };
510 template<class T> struct B : A<T> { int get(); };
get()511 template<> int B<int>::get() { return n; }
512 int k = B<int>().get();
513 }
514
515 namespace dr546 { // dr546: yes
516 template<typename T> struct A { void f(); };
517 template struct A<int>;
f()518 template<typename T> void A<T>::f() { T::error; }
519 }
520
521 namespace dr547 { // dr547: yes
522 // When targeting the MS x86 ABI, the type of a member function includes a
523 // __thiscall qualifier. This is non-conforming, but we still implement
524 // the intent of dr547
525 #if defined(_M_IX86) || (defined(__MINGW32__) && !defined(__MINGW64__))
526 #define THISCALL __thiscall
527 #else
528 #define THISCALL
529 #endif
530
531 template<typename T> struct X;
532 template<typename T> struct X<THISCALL T() const> {};
f(T C::*)533 template<typename T, typename C> X<T> f(T C::*) { return X<T>(); }
534
535 struct S { void f() const; };
536 X<THISCALL void() const> x = f(&S::f);
537
538 #undef THISCALL
539 }
540
541 namespace dr548 { // dr548: dup 482
542 template<typename T> struct S {};
f()543 template<typename T> void f() {}
544 template struct dr548::S<int>;
545 template void dr548::f<int>();
546 }
547
548 namespace dr551 { // dr551: yes c++11
549 // FIXME: This obviously should apply in C++98 mode too.
f()550 template<typename T> void f() {}
551 template inline void f<int>();
552 #if __cplusplus >= 201103L
553 // expected-error@-2 {{cannot be 'inline'}}
554 #endif
555
g()556 template<typename T> inline void g() {}
557 template inline void g<int>();
558 #if __cplusplus >= 201103L
559 // expected-error@-2 {{cannot be 'inline'}}
560 #endif
561
562 template<typename T> struct X {
fdr551::X563 void f() {}
564 };
565 template inline void X<int>::f();
566 #if __cplusplus >= 201103L
567 // expected-error@-2 {{cannot be 'inline'}}
568 #endif
569 }
570
571 namespace dr552 { // dr552: yes
572 template<typename T, typename T::U> struct X {};
573 struct Y { typedef int U; };
574 X<Y, 0> x;
575 }
576
577 struct dr553_class {
578 friend void *operator new(size_t, dr553_class);
579 };
580 namespace dr553 {
581 dr553_class c;
582 // Contrary to the apparent intention of the DR, operator new is not actually
583 // looked up with a lookup mechanism that performs ADL; the standard says it
584 // "is looked up in global scope", where it is not visible.
585 void *p = new (c) int; // expected-error {{no matching function}}
586
587 struct namespace_scope {
588 friend void *operator new(size_t, namespace_scope); // expected-error {{cannot be declared inside a namespace}}
589 };
590 }
591
592 // dr556: na
593
594 namespace dr557 { // dr557: yes
595 template<typename T> struct S {
596 friend void f(S<T> *);
597 friend void g(S<S<T> > *);
598 };
x(S<int> * p,S<S<int>> * q)599 void x(S<int> *p, S<S<int> > *q) {
600 f(p);
601 g(q);
602 }
603 }
604
605 namespace dr558 { // dr558: yes
606 wchar_t a = L'\uD7FF';
607 wchar_t b = L'\xD7FF';
608 wchar_t c = L'\uD800'; // expected-error {{invalid universal character}}
609 wchar_t d = L'\xD800';
610 wchar_t e = L'\uDFFF'; // expected-error {{invalid universal character}}
611 wchar_t f = L'\xDFFF';
612 wchar_t g = L'\uE000';
613 wchar_t h = L'\xE000';
614 }
615
616 template<typename> struct dr559 { typedef int T; dr559::T u; }; // dr559: yes
617
618 namespace dr561 { // dr561: yes
619 template<typename T> void f(int);
g(T t)620 template<typename T> void g(T t) {
621 f<T>(t);
622 }
623 namespace {
624 struct S {};
625 template<typename T> static void f(S);
626 }
h(S s)627 void h(S s) {
628 g(s);
629 }
630 }
631
632 namespace dr564 { // dr564: yes
633 extern "C++" void f(int);
634 void f(int); // ok
635 extern "C++" { extern int n; }
636 int n; // ok
637 }
638
639 namespace dr565 { // dr565: yes
640 namespace N {
641 template<typename T> int f(T); // expected-note {{target}}
642 }
643 using N::f; // expected-note {{using}}
644 template<typename T> int f(T*);
645 template<typename T> void f(T);
646 template<typename T, int = 0> int f(T); // expected-error 0-1{{extension}}
647 template<typename T> int f(T, int = 0);
648 template<typename T> int f(T); // expected-error {{conflicts with}}
649 }
650
651 namespace dr566 { // dr566: yes
652 #if __cplusplus >= 201103L
653 int check[int(-3.99) == -3 ? 1 : -1];
654 #endif
655 }
656
657 // dr567: na
658
659 namespace dr568 { // dr568: yes c++11
660 // FIXME: This is a DR issue against C++98, so should probably apply there
661 // too.
662 struct x { int y; };
663 class trivial : x {
664 x y;
665 public:
666 int n;
667 };
668 int check_trivial[__is_trivial(trivial) ? 1 : -1];
669
670 struct std_layout {
671 std_layout();
672 std_layout(const std_layout &);
673 ~std_layout();
674 private:
675 int n;
676 };
677 int check_std_layout[__is_standard_layout(std_layout) ? 1 : -1];
678
679 struct aggregate {
680 int x;
681 int y;
682 trivial t;
683 std_layout sl;
684 };
685 aggregate aggr = {};
686
687 void f(...);
g(trivial t)688 void g(trivial t) { f(t); }
689 #if __cplusplus < 201103L
690 // expected-error@-2 {{non-POD}}
691 #endif
692
jump()693 void jump() {
694 goto x;
695 #if __cplusplus < 201103L
696 // expected-error@-2 {{cannot jump}}
697 // expected-note@+2 {{non-POD}}
698 #endif
699 trivial t;
700 x: ;
701 }
702 }
703
704 namespace dr569 { // dr569: yes c++11
705 // FIXME: This is a DR issue against C++98, so should probably apply there
706 // too.
707 ;;;;;
708 #if __cplusplus < 201103L
709 // expected-error@-2 {{C++11 extension}}
710 #endif
711 }
712
713 namespace dr570 { // dr570: dup 633
714 int n;
715 int &r = n; // expected-note {{previous}}
716 int &r = n; // expected-error {{redefinition}}
717 }
718
719 namespace dr571 { // dr571 unknown
720 // FIXME: Add a codegen test.
721 typedef int &ir;
722 int n;
723 const ir r = n; // expected-warning {{has no effect}} FIXME: Test if this has internal linkage.
724 }
725
726 namespace dr572 { // dr572: yes
727 enum E { a = 1, b = 2 };
728 int check[a + b == 3 ? 1 : -1];
729 }
730
731 namespace dr573 { // dr573: no
732 void *a;
733 int *b = reinterpret_cast<int*>(a);
734 void (*c)() = reinterpret_cast<void(*)()>(a);
735 void *d = reinterpret_cast<void*>(c);
736 #if __cplusplus < 201103L
737 // expected-error@-3 {{extension}}
738 // expected-error@-3 {{extension}}
739 #endif
f()740 void f() { delete a; } // expected-error {{cannot delete}}
741 int n = d - a; // expected-error {{arithmetic on pointers to void}}
742 // FIXME: This is ill-formed.
743 template<void*> struct S;
744 template<int*> struct T;
745 }
746
747 namespace dr574 { // dr574: yes
748 struct A {
749 A &operator=(const A&) const; // expected-note {{does not match because it is const}}
750 };
751 struct B {
752 B &operator=(const B&) volatile; // expected-note {{nearly matches}}
753 };
754 #if __cplusplus >= 201103L
755 struct C {
756 C &operator=(const C&) &; // expected-note {{not viable}} expected-note {{nearly matches}} expected-note {{here}}
757 };
758 struct D {
759 D &operator=(const D&) &&; // expected-note {{not viable}} expected-note {{nearly matches}} expected-note {{here}}
760 };
test(C c,D d)761 void test(C c, D d) {
762 c = c;
763 C() = c; // expected-error {{no viable}}
764 d = d; // expected-error {{no viable}}
765 D() = d;
766 }
767 #endif
768 struct Test {
769 friend A &A::operator=(const A&); // expected-error {{does not match}}
770 friend B &B::operator=(const B&); // expected-error {{does not match}}
771 #if __cplusplus >= 201103L
772 // FIXME: We shouldn't produce the 'cannot overload' diagnostics here.
773 friend C &C::operator=(const C&); // expected-error {{does not match}} expected-error {{cannot overload}}
774 friend D &D::operator=(const D&); // expected-error {{does not match}} expected-error {{cannot overload}}
775 #endif
776 };
777 }
778
779 namespace dr575 { // dr575: yes
780 template<typename T, typename U = typename T::type> void a(T); void a(...); // expected-error 0-1{{extension}}
781 template<typename T, typename T::type U = 0> void b(T); void b(...); // expected-error 0-1{{extension}}
782 template<typename T, int U = T::value> void c(T); void c(...); // expected-error 0-1{{extension}}
783 template<typename T> void d(T, int = T::value); void d(...); // expected-error {{cannot be used prior to '::'}}
x()784 void x() {
785 a(0);
786 b(0);
787 c(0);
788 d(0); // expected-note {{in instantiation of default function argument}}
789 }
790
791 template<typename T = int&> void f(T* = 0); // expected-error 0-1{{extension}}
792 template<typename T = int> void f(T = 0); // expected-error 0-1{{extension}}
g()793 void g() { f<>(); }
794
795 template<typename T> T &h(T *);
796 template<typename T> T *h(T *);
797 void *p = h((void*)0);
798 }
799
800 namespace dr576 { // dr576: yes
801 typedef void f() {} // expected-error {{function definition declared 'typedef'}}
802 void f(typedef int n); // expected-error {{invalid storage class}}
f(char c)803 void f(char c) { typedef int n; }
804 }
805
806 namespace dr577 { // dr577: yes
807 typedef void V;
808 typedef const void CV;
809 void a(void);
810 void b(const void); // expected-error {{qualifiers}}
811 void c(V);
812 void d(CV); // expected-error {{qualifiers}}
813 void (*e)(void) = c;
814 void (*f)(const void); // expected-error {{qualifiers}}
815 void (*g)(V) = a;
816 void (*h)(CV); // expected-error {{qualifiers}}
817 template<typename T> void i(T); // expected-note 2{{requires 1 arg}}
818 template<typename T> void j(void (*)(T)); // expected-note 2{{argument may not have 'void' type}}
k()819 void k() {
820 a();
821 c();
822 i<void>(); // expected-error {{no match}}
823 i<const void>(); // expected-error {{no match}}
824 j<void>(0); // expected-error {{no match}}
825 j<const void>(0); // expected-error {{no match}}
826 }
827 }
828
829 namespace dr580 { // dr580: no
830 class C;
831 struct A { static C c; };
832 struct B { static C c; };
833 class C {
834 C(); // expected-note {{here}}
835 ~C(); // expected-note {{here}}
836
837 typedef int I; // expected-note {{here}}
838 template<int> struct X;
839 template<int> friend struct Y;
840 template<int> void f();
841 template<int> friend void g();
842 friend struct A;
843 };
844
845 template<C::I> struct C::X {};
846 template<C::I> struct Y {};
847 template<C::I> struct Z {}; // FIXME: should reject, accepted because C befriends A!
848
f()849 template<C::I> void C::f() {}
g()850 template<C::I> void g() {}
h()851 template<C::I> void h() {} // expected-error {{private}}
852
853 C A::c;
854 C B::c; // expected-error 2{{private}}
855 }
856
857 // dr582: na
858
859 namespace dr583 { // dr583: no
860 // see n3624
861 int *p;
862 // FIXME: These are all ill-formed.
863 bool b1 = p < 0;
864 bool b2 = p > 0;
865 bool b3 = p <= 0;
866 bool b4 = p >= 0;
867 }
868
869 // dr584: na
870
871 namespace dr585 { // dr585: yes
872 template<typename> struct T;
873 struct A {
874 friend T; // expected-error {{requires a type specifier}} expected-error {{can only be classes or functions}}
875 // FIXME: It's not clear whether the standard allows this or what it means,
876 // but the DR585 writeup suggests it as an alternative.
877 template<typename U> friend T<U>; // expected-error {{must use an elaborated type}}
878 };
879 template<template<typename> class T> struct B {
880 friend T; // expected-error {{requires a type specifier}} expected-error {{can only be classes or functions}}
881 template<typename U> friend T<U>; // expected-error {{must use an elaborated type}}
882 };
883 }
884
885 // dr586: na
886
887 namespace dr587 { // dr587: yes
f(bool b,const T x,T y)888 template<typename T> void f(bool b, const T x, T y) {
889 const T *p = &(b ? x : y);
890 }
891 struct S {};
892 template void f(bool, const int, int);
893 template void f(bool, const S, S);
894 }
895
896 namespace dr588 { // dr588: yes
897 struct A { int n; }; // expected-note {{ambiguous}}
f()898 template<typename T> int f() {
899 struct S : A, T { int f() { return n; } } s;
900 int a = s.f();
901 int b = s.n; // expected-error {{found in multiple}}
902 }
903 struct B { int n; }; // expected-note {{ambiguous}}
904 int k = f<B>(); // expected-note {{here}}
905 }
906
907 namespace dr589 { // dr589: yes
908 struct B { };
909 struct D : B { };
910 D f();
911 extern const B &b;
912 bool a;
913 const B *p = &(a ? f() : b); // expected-error {{temporary}}
914 const B *q = &(a ? D() : b); // expected-error {{temporary}}
915 }
916
917 namespace dr590 { // dr590: yes
918 template<typename T> struct A {
919 struct B {
920 struct C {
921 A<T>::B::C f(A<T>::B::C); // ok, no 'typename' required.
922 };
923 };
924 };
f(A<T>::B::C)925 template<typename T> typename A<T>::B::C A<T>::B::C::f(A<T>::B::C) {}
926 }
927
928 namespace dr591 { // dr591: no
929 template<typename T> struct A {
930 typedef int M;
931 struct B {
932 typedef void M;
933 struct C;
934 };
935 };
936
937 template<typename T> struct A<T>::B::C : A<T> {
938 // FIXME: Should find member of non-dependent base class A<T>.
939 M m; // expected-error {{incomplete type 'M' (aka 'void'}}
940 };
941 }
942
943 // dr592: na
944 // dr593 needs an IRGen test.
945 // dr594: na
946
947 namespace dr595 { // dr595: dup 1330
948 template<class T> struct X {
fdr595::X949 void f() throw(T) {}
950 };
951 struct S {
952 X<S> xs;
953 };
954 }
955
956 // dr597: na
957
958 namespace dr598 { // dr598: yes
959 namespace N {
960 void f(int);
961 void f(char);
962 // Not found by ADL.
963 void g(void (*)(int));
964 void h(void (*)(int));
965
966 namespace M {
967 struct S {};
968 int &h(void (*)(S));
969 }
970 void i(M::S);
971 void i();
972 }
973 int &g(void(*)(char));
974 int &r = g(N::f);
975 int &s = h(N::f); // expected-error {{undeclared}}
976 int &t = h(N::i);
977 }
978
979 namespace dr599 { // dr599: partial
980 typedef int Fn();
981 struct S { operator void*(); };
982 struct T { operator Fn*(); };
983 struct U { operator int*(); operator void*(); }; // expected-note 2{{conversion}}
984 struct V { operator int*(); operator Fn*(); };
f(void * p,void (* q)(),S s,T t,U u,V v)985 void f(void *p, void (*q)(), S s, T t, U u, V v) {
986 delete p; // expected-error {{cannot delete}}
987 delete q; // expected-error {{cannot delete}}
988 delete s; // expected-error {{cannot delete}}
989 delete t; // expected-error {{cannot delete}}
990 // FIXME: This is valid, but is rejected due to a non-conforming GNU
991 // extension allowing deletion of pointers to void.
992 delete u; // expected-error {{ambiguous}}
993 delete v;
994 }
995 }
996