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