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++1y %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4
5 // PR13819 -- __SIZE_TYPE__ is incompatible.
6 typedef __SIZE_TYPE__ size_t; // expected-error 0-1 {{extension}}
7
8 #if __cplusplus < 201103L
9 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
10 #else
11 #define fold
12 #endif
13
14 namespace dr200 { // dr200: dup 214
15 template <class T> T f(int);
16 template <class T, class U> T f(U) = delete; // expected-error 0-1{{extension}}
17
g()18 void g() {
19 f<int>(1);
20 }
21 }
22
23 // dr201 FIXME: write codegen test
24
25 namespace dr202 { // dr202: yes
26 template<typename T> T f();
27 template<int (*g)()> struct X {
28 int arr[fold(g == &f<int>) ? 1 : -1];
29 };
30 template struct X<f>;
31 }
32
33 // FIXME (export) dr204: no
34
35 namespace dr206 { // dr206: yes
36 struct S; // expected-note 2{{declaration}}
37 template<typename T> struct Q { S s; }; // expected-error {{incomplete}}
f()38 template<typename T> void f() { S s; } // expected-error {{incomplete}}
39 }
40
41 namespace dr207 { // dr207: yes
42 class A {
43 protected:
f()44 static void f() {}
45 };
46 class B : A {
47 public:
48 using A::f;
g()49 void g() {
50 A::f();
51 f();
52 }
53 };
54 }
55
56 // dr208 FIXME: write codegen test
57
58 namespace dr209 { // dr209: yes
59 class A {
60 void f(); // expected-note {{here}}
61 };
62 class B {
63 friend void A::f(); // expected-error {{private}}
64 };
65 }
66
67 // dr210 FIXME: write codegen test
68
69 namespace dr211 { // dr211: yes
70 struct A {
Adr211::A71 A() try {
72 throw 0;
73 } catch (...) {
74 return; // expected-error {{return in the catch of a function try block of a constructor}}
75 }
76 };
77 }
78
79 namespace dr213 { // dr213: yes
80 template <class T> struct A : T {
hdr213::A81 void h(T t) {
82 char &r1 = f(t);
83 int &r2 = g(t); // expected-error {{undeclared}}
84 }
85 };
86 struct B {
87 int &f(B);
88 int &g(B); // expected-note {{in dependent base class}}
89 };
90 char &f(B);
91
92 template void A<B>::h(B); // expected-note {{instantiation}}
93 }
94
95 namespace dr214 { // dr214: yes
checked_cast(U from)96 template<typename T, typename U> T checked_cast(U from) { U::error; }
97 template<typename T, typename U> T checked_cast(U *from);
98 class C {};
foo(int * arg)99 void foo(int *arg) { checked_cast<const C *>(arg); }
100
101 template<typename T> T f(int);
f(U)102 template<typename T, typename U> T f(U) { T::error; }
g()103 void g() {
104 f<int>(1);
105 }
106 }
107
108 namespace dr215 { // dr215: yes
109 template<typename T> class X {
110 friend void T::foo();
111 int n;
112 };
113 struct Y {
foodr215::Y114 void foo() { (void)+X<Y>().n; }
115 };
116 }
117
118 namespace dr216 { // dr216: no
119 // FIXME: Should reject this: 'f' has linkage but its type does not,
120 // and 'f' is odr-used but not defined in this TU.
121 typedef enum { e } *E;
122 void f(E);
g(E e)123 void g(E e) { f(e); }
124
125 struct S {
126 // FIXME: Should reject this: 'f' has linkage but its type does not,
127 // and 'f' is odr-used but not defined in this TU.
128 typedef enum { e } *E;
129 void f(E);
130 };
g(S s,S::E e)131 void g(S s, S::E e) { s.f(e); }
132 }
133
134 namespace dr217 { // dr217: yes
135 template<typename T> struct S {
136 void f(int);
137 };
f(int=0)138 template<typename T> void S<T>::f(int = 0) {} // expected-error {{default arguments cannot be added}}
139 }
140
141 namespace dr218 { // dr218: yes
142 namespace A {
143 struct S {};
144 void f(S);
145 }
146 namespace B {
147 struct S {};
148 void f(S);
149 }
150
151 struct C {
152 int f;
test1dr218::C153 void test1(A::S as) { f(as); } // expected-error {{called object type 'int'}}
test2dr218::C154 void test2(A::S as) { void f(); f(as); } // expected-error {{too many arguments}} expected-note {{}}
test3dr218::C155 void test3(A::S as) { using A::f; f(as); } // ok
test4dr218::C156 void test4(A::S as) { using B::f; f(as); } // ok
test5dr218::C157 void test5(A::S as) { int f; f(as); } // expected-error {{called object type 'int'}}
test6dr218::C158 void test6(A::S as) { struct f {}; (void) f(as); } // expected-error {{no matching conversion}} expected-note +{{}}
159 };
160
161 namespace D {
162 struct S {};
163 struct X { void operator()(S); } f;
164 }
testD(D::S ds)165 void testD(D::S ds) { f(ds); } // expected-error {{undeclared identifier}}
166
167 namespace E {
168 struct S {};
169 struct f { f(S); };
170 }
testE(E::S es)171 void testE(E::S es) { f(es); } // expected-error {{undeclared identifier}}
172
173 namespace F {
174 struct S {
f(S,T)175 template<typename T> friend void f(S, T) {}
176 };
177 }
testF(F::S fs)178 void testF(F::S fs) { f(fs, 0); }
179
180 namespace G {
181 namespace X {
182 int f;
183 struct A {};
184 }
185 namespace Y {
186 template<typename T> void f(T);
187 struct B {};
188 }
189 template<typename A, typename B> struct C {};
190 }
testG(G::C<G::X::A,G::Y::B> gc)191 void testG(G::C<G::X::A, G::Y::B> gc) { f(gc); }
192 }
193
194 // dr219: na
195 // dr220: na
196
197 namespace dr221 { // dr221: yes
198 struct A {
199 A &operator=(int&);
200 A &operator+=(int&);
201 static A &operator=(A&, double&); // expected-error {{cannot be a static member}}
202 static A &operator+=(A&, double&); // expected-error {{cannot be a static member}}
203 friend A &operator=(A&, char&); // expected-error {{must be a non-static member function}}
204 friend A &operator+=(A&, char&);
205 };
206 A &operator=(A&, float&); // expected-error {{must be a non-static member function}}
207 A &operator+=(A&, float&);
208
test(A a,int n,char c,float f)209 void test(A a, int n, char c, float f) {
210 a = n;
211 a += n;
212 a = c;
213 a += c;
214 a = f;
215 a += f;
216 }
217 }
218
219 namespace dr222 { // dr222: dup 637
f(int a,int b,int c,int * x)220 void f(int a, int b, int c, int *x) {
221 #pragma clang diagnostic push
222 #pragma clang diagnostic warning "-Wunsequenced"
223 void((a += b) += c);
224 void((a += b) + (a += c)); // expected-warning {{multiple unsequenced modifications to 'a'}}
225
226 x[a++] = a; // expected-warning {{unsequenced modification and access to 'a'}}
227
228 a = b = 0; // ok, read and write of 'b' are sequenced
229
230 a = (b = a++); // expected-warning {{multiple unsequenced modifications to 'a'}}
231 a = (b = ++a);
232 #pragma clang diagnostic pop
233 }
234 }
235
236 // dr223: na
237
238 namespace dr224 { // dr224: no
239 namespace example1 {
240 template <class T> class A {
241 typedef int type;
242 A::type a;
243 A<T>::type b;
244 A<T*>::type c; // expected-error {{missing 'typename'}}
245 ::dr224::example1::A<T>::type d;
246
247 class B {
248 typedef int type;
249
250 A::type a;
251 A<T>::type b;
252 A<T*>::type c; // expected-error {{missing 'typename'}}
253 ::dr224::example1::A<T>::type d;
254
255 B::type e;
256 A<T>::B::type f;
257 A<T*>::B::type g; // expected-error {{missing 'typename'}}
258 typename A<T*>::B::type h;
259 };
260 };
261
262 template <class T> class A<T*> {
263 typedef int type;
264 A<T*>::type a;
265 A<T>::type b; // expected-error {{missing 'typename'}}
266 };
267
268 template <class T1, class T2, int I> struct B {
269 typedef int type;
270 B<T1, T2, I>::type b1;
271 B<T2, T1, I>::type b2; // expected-error {{missing 'typename'}}
272
273 typedef T1 my_T1;
274 static const int my_I = I;
275 static const int my_I2 = I+0;
276 static const int my_I3 = my_I;
277 B<my_T1, T2, my_I>::type b3; // FIXME: expected-error {{missing 'typename'}}
278 B<my_T1, T2, my_I2>::type b4; // expected-error {{missing 'typename'}}
279 B<my_T1, T2, my_I3>::type b5; // FIXME: expected-error {{missing 'typename'}}
280 };
281 }
282
283 namespace example2 {
284 template <int, typename T> struct X { typedef T type; };
285 template <class T> class A {
286 static const int i = 5;
287 X<i, int>::type w; // FIXME: expected-error {{missing 'typename'}}
288 X<A::i, char>::type x; // FIXME: expected-error {{missing 'typename'}}
289 X<A<T>::i, double>::type y; // FIXME: expected-error {{missing 'typename'}}
290 X<A<T*>::i, long>::type z; // expected-error {{missing 'typename'}}
291 int f();
292 };
f()293 template <class T> int A<T>::f() {
294 return i;
295 }
296 }
297 }
298
299 // dr225: yes
dr225_f(T t)300 template<typename T> void dr225_f(T t) { dr225_g(t); } // expected-error {{call to function 'dr225_g' that is neither visible in the template definition nor found by argument-dependent lookup}}
301 void dr225_g(int); // expected-note {{should be declared prior to the call site}}
302 template void dr225_f(int); // expected-note {{in instantiation of}}
303
304 namespace dr226 { // dr226: no
f()305 template<typename T = void> void f() {}
306 #if __cplusplus < 201103L
307 // expected-error@-2 {{extension}}
308 // FIXME: This appears to be wrong: default arguments for function templates
309 // are listed as a defect (in c++98) not an extension. EDG accepts them in
310 // strict c++98 mode.
311 #endif
312 template<typename T> struct S {
313 template<typename U = void> void g();
314 #if __cplusplus < 201103L
315 // expected-error@-2 {{extension}}
316 #endif
317 template<typename U> struct X;
318 template<typename U> void h();
319 };
g()320 template<typename T> template<typename U> void S<T>::g() {}
321 template<typename T> template<typename U = void> struct S<T>::X {}; // expected-error {{cannot add a default template arg}}
h()322 template<typename T> template<typename U = void> void S<T>::h() {} // expected-error {{cannot add a default template arg}}
323
324 template<typename> void friend_h();
325 struct A {
326 // FIXME: This is ill-formed.
327 template<typename=void> struct friend_B;
328 // FIXME: f, h, and i are ill-formed.
329 // f is ill-formed because it is not a definition.
330 // h and i are ill-formed because they are not the only declarations of the
331 // function in the translation unit.
332 template<typename=void> void friend_f();
friend_gdr226::A333 template<typename=void> void friend_g() {}
friend_hdr226::A334 template<typename=void> void friend_h() {}
friend_idr226::A335 template<typename=void> void friend_i() {}
336 #if __cplusplus < 201103L
337 // expected-error@-5 {{extension}} expected-error@-4 {{extension}}
338 // expected-error@-4 {{extension}} expected-error@-3 {{extension}}
339 #endif
340 };
341 template<typename> void friend_i();
342
foo(X)343 template<typename=void, typename X> void foo(X) {}
344 template<typename=void, typename X> struct Foo {}; // expected-error {{missing a default argument}} expected-note {{here}}
345 #if __cplusplus < 201103L
346 // expected-error@-3 {{extension}}
347 #endif
348
349 template<typename=void, typename X, typename, typename Y> int foo(X, Y);
350 template<typename, typename X, typename=void, typename Y> int foo(X, Y);
351 int x = foo(0, 0);
352 #if __cplusplus < 201103L
353 // expected-error@-4 {{extension}}
354 // expected-error@-4 {{extension}}
355 #endif
356 }
357
dr227(bool b)358 void dr227(bool b) { // dr227: yes
359 if (b)
360 int n;
361 else
362 int n;
363 }
364
365 namespace dr228 { // dr228: yes
366 template <class T> struct X {
367 void f();
368 };
369 template <class T> struct Y {
gdr228::Y370 void g(X<T> x) { x.template X<T>::f(); }
371 };
372 }
373
374 namespace dr229 { // dr229: yes
375 template<typename T> void f();
f()376 template<typename T> void f<T*>() {} // expected-error {{function template partial specialization}}
f()377 template<> void f<int>() {}
378 }
379
380 namespace dr230 { // dr230: yes
381 struct S {
Sdr230::S382 S() { f(); } // expected-warning {{call to pure virtual member function}}
383 virtual void f() = 0; // expected-note {{declared here}}
384 };
385 }
386
387 namespace dr231 { // dr231: yes
388 namespace outer {
389 namespace inner {
390 int i; // expected-note {{here}}
391 }
f()392 void f() { using namespace inner; }
393 int j = i; // expected-error {{undeclared identifier 'i'; did you mean 'inner::i'?}}
394 }
395 }
396
397 // dr234: na
398 // dr235: na
399
400 namespace dr236 { // dr236: yes
401 void *p = int();
402 #if __cplusplus < 201103L
403 // expected-warning@-2 {{null pointer}}
404 #else
405 // expected-error@-4 {{cannot initialize}}
406 #endif
407 }
408
409 namespace dr237 { // dr237: dup 470
fdr237::A410 template<typename T> struct A { void f() { T::error; } };
411 template<typename T> struct B : A<T> {};
412 template struct B<int>; // ok
413 }
414
415 namespace dr239 { // dr239: yes
416 namespace NS {
417 class T {};
418 void f(T);
419 float &g(T, int);
420 }
421 NS::T parm;
422 int &g(NS::T, float);
main()423 int main() {
424 f(parm);
425 float &r = g(parm, 1);
426 extern int &g(NS::T, float);
427 int &s = g(parm, 1);
428 }
429 }
430
431 // dr240: dup 616
432
433 namespace dr241 { // dr241: yes
434 namespace A {
435 struct B {};
436 template <int X> void f(); // expected-note 2{{candidate}}
437 template <int X> void g(B);
438 }
439 namespace C {
440 template <class T> void f(T t); // expected-note 2{{candidate}}
441 template <class T> void g(T t); // expected-note {{candidate}}
442 }
h(A::B b)443 void h(A::B b) {
444 f<3>(b); // expected-error {{undeclared identifier}}
445 g<3>(b); // expected-error {{undeclared identifier}}
446 A::f<3>(b); // expected-error {{no matching}}
447 A::g<3>(b);
448 C::f<3>(b); // expected-error {{no matching}}
449 C::g<3>(b); // expected-error {{no matching}}
450 using C::f;
451 using C::g;
452 f<3>(b); // expected-error {{no matching}}
453 g<3>(b);
454 }
455 }
456
457 namespace dr243 { // dr243: yes
458 struct B;
459 struct A {
460 A(B); // expected-note {{candidate}}
461 };
462 struct B {
463 operator A() = delete; // expected-error 0-1{{extension}} expected-note {{candidate}}
464 } b;
465 A a1(b);
466 A a2 = b; // expected-error {{ambiguous}}
467 }
468
469 namespace dr244 { // dr244: 3.5
470 struct B {}; struct D : B {}; // expected-note {{here}}
471
472 D D_object;
473 typedef B B_alias;
474 B* B_ptr = &D_object;
475
f()476 void f() {
477 D_object.~B(); // expected-error {{expression does not match the type}}
478 D_object.B::~B();
479 B_ptr->~B();
480 B_ptr->~B_alias();
481 B_ptr->B_alias::~B();
482 // This is valid under DR244.
483 B_ptr->B_alias::~B_alias();
484 B_ptr->dr244::~B(); // expected-error {{refers to a member in namespace}}
485 B_ptr->dr244::~B_alias(); // expected-error {{refers to a member in namespace}}
486 }
487 }
488
489 namespace dr245 { // dr245: yes
490 struct S {
491 enum E {}; // expected-note {{here}}
492 class E *p; // expected-error {{does not match previous declaration}}
493 };
494 }
495
496 namespace dr246 { // dr246: yes
497 struct S {
Sdr246::S498 S() try { // expected-note {{try block}}
499 throw 0;
500 X: ;
501 } catch (int) {
502 goto X; // expected-error {{protected scope}}
503 }
504 };
505 }
506
507 namespace dr247 { // dr247: yes
508 struct A {};
509 struct B : A {
510 void f();
511 void f(int);
512 };
513 void (A::*f)() = (void (A::*)())&B::f;
514
515 struct C {
516 void f();
517 void f(int);
518 };
519 struct D : C {};
520 void (C::*g)() = &D::f;
521 void (D::*h)() = &D::f;
522
523 struct E {
524 void f();
525 };
526 struct F : E {
527 using E::f;
528 void f(int);
529 };
530 void (F::*i)() = &F::f;
531 }
532
533 namespace dr248 { // dr248: yes c++11
534 // FIXME: Should this also apply to c++98 mode? This was a DR against C++98.
535 int \u040d\u040e = 0;
536 #if __cplusplus < 201103L
537 // FIXME: expected-error@-2 {{expected ';'}}
538 #endif
539 }
540
541 namespace dr249 { // dr249: yes
542 template<typename T> struct X { void f(); };
f()543 template<typename T> void X<T>::f() {}
544 }
545
546 namespace dr250 { // dr250: yes
547 typedef void (*FPtr)(double x[]);
548
549 template<int I> void f(double x[]);
550 FPtr fp = &f<3>;
551
552 template<int I = 3> void g(double x[]); // expected-error 0-1{{extension}}
553 FPtr gp = &g<>;
554 }
555
556 namespace dr252 { // dr252: yes
557 struct A {
558 void operator delete(void*); // expected-note {{found}}
559 };
560 struct B {
561 void operator delete(void*); // expected-note {{found}}
562 };
563 struct C : A, B {
564 virtual ~C();
565 };
~C()566 C::~C() {} // expected-error {{'operator delete' found in multiple base classes}}
567
568 struct D {
569 void operator delete(void*, int); // expected-note {{here}}
570 virtual ~D();
571 };
~D()572 D::~D() {} // expected-error {{no suitable member 'operator delete'}}
573
574 struct E {
575 void operator delete(void*, int);
576 void operator delete(void*) = delete; // expected-error 0-1{{extension}} expected-note 1-2 {{here}}
577 virtual ~E(); // expected-error 0-1 {{attempt to use a deleted function}}
578 };
~E()579 E::~E() {} // expected-error {{attempt to use a deleted function}}
580
581 struct F {
582 // If both functions are available, the first one is a placement delete.
583 void operator delete(void*, size_t);
584 void operator delete(void*) = delete; // expected-error 0-1{{extension}} expected-note {{here}}
585 virtual ~F();
586 };
~F()587 F::~F() {} // expected-error {{attempt to use a deleted function}}
588
589 struct G {
590 void operator delete(void*, size_t);
591 virtual ~G();
592 };
~G()593 G::~G() {}
594 }
595
596 namespace dr254 { // dr254: yes
597 template<typename T> struct A {
598 typedef typename T::type type; // ok even if this is a typedef-name, because
599 // it's not an elaborated-type-specifier
600 typedef struct T::type foo; // expected-error {{elaborated type refers to a typedef}}
601 };
602 struct B { struct type {}; };
603 struct C { typedef struct {} type; }; // expected-note {{here}}
604 A<B>::type n;
605 A<C>::type n; // expected-note {{instantiation of}}
606 }
607
608 // dr256: dup 624
609
610 namespace dr257 { // dr257: yes
611 struct A { A(int); }; // expected-note {{here}}
612 struct B : virtual A {
Bdr257::B613 B() {}
614 virtual void f() = 0;
615 };
616 struct C : B {
Cdr257::C617 C() {}
618 };
619 struct D : B {
Ddr257::D620 D() {} // expected-error {{must explicitly initialize the base class 'dr257::A'}}
621 void f();
622 };
623 }
624
625 namespace dr258 { // dr258: yes
626 struct A {
627 void f(const int);
628 template<typename> void g(int);
629 float &h() const;
630 };
631 struct B : A {
632 using A::f;
633 using A::g;
634 using A::h;
635 int &f(int);
636 template<int> int &g(int); // expected-note {{candidate}}
637 int &h();
638 } b;
639 int &w = b.f(0);
640 int &x = b.g<int>(0); // expected-error {{no match}}
641 int &y = b.h();
642 float &z = const_cast<const B&>(b).h();
643
644 struct C {
645 virtual void f(const int) = 0;
646 };
647 struct D : C {
648 void f(int);
649 } d;
650
651 struct E {
652 virtual void f() = 0; // expected-note {{unimplemented}}
653 };
654 struct F : E {
fdr258::F655 void f() const {}
656 } f; // expected-error {{abstract}}
657 }
658
659 namespace dr259 { // dr259: yes c++11
660 template<typename T> struct A {};
661 template struct A<int>; // expected-note {{previous}}
662 template struct A<int>; // expected-error {{duplicate explicit instantiation}}
663
664 // FIXME: We only apply this DR in C++11 mode.
665 template<> struct A<float>;
666 template struct A<float>;
667 #if __cplusplus < 201103L
668 // expected-error@-2 {{extension}} expected-note@-3 {{here}}
669 #endif
670
671 template struct A<char>; // expected-note {{here}}
672 template<> struct A<char>; // expected-error {{explicit specialization of 'dr259::A<char>' after instantiation}}
673
674 template<> struct A<double>;
675 template<> struct A<double>;
676 template<> struct A<double> {}; // expected-note {{here}}
677 template<> struct A<double> {}; // expected-error {{redefinition}}
678
679 template<typename T> struct B; // expected-note {{here}}
680 template struct B<int>; // expected-error {{undefined}}
681
682 template<> struct B<float>;
683 template struct B<float>;
684 #if __cplusplus < 201103L
685 // expected-error@-2 {{extension}} expected-note@-3 {{here}}
686 #endif
687 }
688
689 // FIXME: When dr260 is resolved, also add tests for DR507.
690
691 namespace dr261 { // dr261: no
692 #pragma clang diagnostic push
693 #pragma clang diagnostic warning "-Wused-but-marked-unused"
694
695 // FIXME: This is ill-formed, with a diagnostic required, because operator new
696 // and operator delete are inline and odr-used, but not defined in this
697 // translation unit.
698 // We're also missing the -Wused-but-marked-unused diagnostic here.
699 struct A {
700 inline void *operator new(size_t) __attribute__((unused));
701 inline void operator delete(void*) __attribute__((unused));
Adr261::A702 A() {}
703 };
704
705 // FIXME: These are ill-formed, with a required diagnostic, for the same
706 // reason.
707 struct B {
708 inline void operator delete(void*) __attribute__((unused));
~Bdr261::B709 ~B() {}
710 };
711 struct C {
712 inline void operator delete(void*) __attribute__((unused));
~Cdr261::C713 virtual ~C() {}
714 };
715
716 struct D {
717 inline void operator delete(void*) __attribute__((unused));
718 };
h()719 void h() { C::operator delete(0); } // expected-warning {{marked unused but was used}}
720
721 #pragma clang diagnostic pop
722 }
723
724 namespace dr262 { // dr262: yes
725 int f(int = 0, ...);
726 int k = f();
727 int l = f(0);
728 int m = f(0, 0);
729 }
730
731 namespace dr263 { // dr263: yes
732 struct X {};
733 struct Y {
734 #if __cplusplus < 201103L
735 friend X::X() throw();
736 friend X::~X() throw();
737 #else
738 friend constexpr X::X() noexcept;
739 friend X::~X();
740 #endif
741 Y::Y(); // expected-error {{extra qualification}}
742 Y::~Y(); // expected-error {{extra qualification}}
743 };
744 }
745
746 // dr265: dup 353
747 // dr266: na
748 // dr269: na
749 // dr270: na
750
751 namespace dr272 { // dr272: yes
752 struct X {
fdr272::X753 void f() {
754 this->~X();
755 X::~X();
756 ~X(); // expected-error {{unary expression}}
757 }
758 };
759 }
760
761 #include <stdarg.h>
762 #include <stddef.h>
763 namespace dr273 { // dr273: yes
764 struct A {
765 int n;
766 };
767 void operator&(A);
f(A a,...)768 void f(A a, ...) {
769 offsetof(A, n);
770 va_list val;
771 va_start(val, a);
772 va_end(val);
773 }
774 }
775
776 // dr274: na
777
778 namespace dr275 { // dr275: no
779 namespace N {
f(T)780 template <class T> void f(T) {} // expected-note 1-4{{here}}
g(T)781 template <class T> void g(T) {} // expected-note {{candidate}}
782 template <> void f(int);
783 template <> void f(char);
784 template <> void f(double);
785 template <> void g(char);
786 }
787
788 using namespace N;
789
790 namespace M {
f(char)791 template <> void N::f(char) {} // expected-error {{'M' does not enclose namespace 'N'}}
g(T)792 template <class T> void g(T) {}
g(char)793 template <> void g(char) {}
794 template void f(long);
795 #if __cplusplus >= 201103L
796 // FIXME: this should be rejected in c++98 too
797 // expected-error@-3 {{must occur in namespace 'N'}}
798 #endif
799 template void N::f(unsigned long);
800 #if __cplusplus >= 201103L
801 // FIXME: this should be rejected in c++98 too
802 // expected-error@-3 {{not in a namespace enclosing 'N'}}
803 #endif
804 template void h(long); // expected-error {{does not refer to a function template}}
f(double)805 template <> void f(double) {} // expected-error {{no function template matches}}
806 }
807
g(T)808 template <class T> void g(T) {} // expected-note {{candidate}}
809
f(char)810 template <> void N::f(char) {}
f(int)811 template <> void f(int) {} // expected-error {{no function template matches}}
812
813 template void f(short);
814 #if __cplusplus >= 201103L
815 // FIXME: this should be rejected in c++98 too
816 // expected-error@-3 {{must occur in namespace 'N'}}
817 #endif
818 template void N::f(unsigned short);
819
820 // FIXME: this should probably be valid. the wording from the issue
821 // doesn't clarify this, but it follows from the usual rules.
822 template void g(int); // expected-error {{ambiguous}}
823
824 // FIXME: likewise, this should also be valid.
f(T)825 template<typename T> void f(T) {} // expected-note {{candidate}}
826 template void f(short); // expected-error {{ambiguous}}
827 }
828
829 // dr276: na
830
831 namespace dr277 { // dr277: yes
832 typedef int *intp;
833 int *p = intp();
834 int a[fold(intp() ? -1 : 1)];
835 }
836
837 namespace dr280 { // dr280: yes
838 typedef void f0();
839 typedef void f1(int);
840 typedef void f2(int, int);
841 typedef void f3(int, int, int);
842 struct A {
843 operator f1*(); // expected-note {{here}} expected-note {{candidate}}
844 operator f2*();
845 };
846 struct B {
847 operator f0*(); // expected-note {{candidate}}
848 private:
849 operator f3*(); // expected-note {{here}} expected-note {{candidate}}
850 };
851 struct C {
852 operator f0*(); // expected-note {{candidate}}
853 operator f1*(); // expected-note {{candidate}}
854 operator f2*(); // expected-note {{candidate}}
855 operator f3*(); // expected-note {{candidate}}
856 };
857 struct D : private A, B { // expected-note 2{{here}}
858 operator f2*(); // expected-note {{candidate}}
859 } d;
860 struct E : C, D {} e;
g()861 void g() {
862 d(); // ok, public
863 d(0); // expected-error {{private member of 'dr280::A'}} expected-error {{private base class 'dr280::A'}}
864 d(0, 0); // ok, suppressed by member in D
865 d(0, 0, 0); // expected-error {{private member of 'dr280::B'}}
866 e(); // expected-error {{ambiguous}}
867 e(0); // expected-error {{ambiguous}}
868 e(0, 0); // expected-error {{ambiguous}}
869 e(0, 0, 0); // expected-error {{ambiguous}}
870 }
871 }
872
873 namespace dr281 { // dr281: no
874 void a();
875 inline void b();
876
877 void d();
878 inline void e();
879
880 struct S {
881 friend inline void a(); // FIXME: ill-formed
882 friend inline void b();
883 friend inline void c(); // FIXME: ill-formed
d()884 friend inline void d() {}
e()885 friend inline void e() {}
f()886 friend inline void f() {}
887 };
888 }
889
890 namespace dr283 { // dr283: yes
891 template<typename T> // expected-note 2{{here}}
892 struct S {
893 friend class T; // expected-error {{shadows}}
894 class T; // expected-error {{shadows}}
895 };
896 }
897
898 namespace dr284 { // dr284: no
899 namespace A {
900 struct X;
901 enum Y {};
902 class Z {};
903 }
904 namespace B {
905 struct W;
906 using A::X;
907 using A::Y;
908 using A::Z;
909 }
910 struct B::V {}; // expected-error {{no struct named 'V'}}
911 struct B::W {};
912 struct B::X {}; // FIXME: ill-formed
913 enum B::Y e; // ok per dr417
914 class B::Z z; // ok per dr417
915
916 struct C {
917 struct X;
918 enum Y {};
919 class Z {};
920 };
921 struct D : C {
922 struct W;
923 using C::X;
924 using C::Y;
925 using C::Z;
926 };
927 struct D::V {}; // expected-error {{no struct named 'V'}}
928 struct D::W {};
929 struct D::X {}; // FIXME: ill-formed
930 enum D::Y e2; // ok per dr417
931 class D::Z z2; // ok per dr417
932 }
933
934 namespace dr285 { // dr285: yes
935 template<typename T> void f(T, int); // expected-note {{match}}
936 template<typename T> void f(int, T); // expected-note {{match}}
f(int,int)937 template<> void f<int>(int, int) {} // expected-error {{ambiguous}}
938 }
939
940 namespace dr286 { // dr286: yes
941 template<class T> struct A {
942 class C {
943 template<class T2> struct B {}; // expected-note {{here}}
944 };
945 };
946
947 template<class T>
948 template<class T2>
949 struct A<T>::C::B<T2*> { };
950
951 A<short>::C::B<int*> absip; // expected-error {{private}}
952 }
953
954 // dr288: na
955
956 namespace dr289 { // dr289: yes
957 struct A; // expected-note {{forward}}
958 struct B : A {}; // expected-error {{incomplete}}
959
960 template<typename T> struct C { typename T::error error; }; // expected-error {{cannot be used prior to '::'}}
961 struct D : C<int> {}; // expected-note {{instantiation}}
962 }
963
964 // dr290: na
965 // dr291: dup 391
966 // dr292 FIXME: write a codegen test
967
968 namespace dr294 { // dr294: no
969 void f() throw(int);
main()970 int main() {
971 // FIXME: we reject this for the wrong reason, because we don't implement
972 // dr87 yet.
973 (void)static_cast<void (*)() throw()>(f); // expected-error {{not superset}}
974 void (*p)() throw() = f; // expected-error {{not superset}}
975
976 (void)static_cast<void (*)() throw(int)>(f); // FIXME: ill-formed
977 }
978 }
979
980 namespace dr295 { // dr295: no
981 typedef int f();
982 // FIXME: This warning is incorrect.
983 const f g; // expected-warning {{unspecified behavior}}
984 const f &r = g; // expected-warning {{unspecified behavior}}
985 template<typename T> struct X {
986 const T &f;
987 };
988 X<f> x = {g}; // FIXME: expected-error {{drops qualifiers}}
989 }
990
991 namespace dr296 { // dr296: yes
992 struct A {
operator intdr296::A993 static operator int() { return 0; } // expected-error {{static}}
994 };
995 }
996
997 namespace dr298 { // dr298: yes
998 struct A {
999 typedef int type;
1000 A();
1001 ~A();
1002 };
1003 typedef A B; // expected-note {{here}}
1004 typedef const A C; // expected-note {{here}}
1005
1006 A::type i1;
1007 B::type i2;
1008 C::type i3;
1009
1010 struct A a;
1011 struct B b; // expected-error {{refers to a typedef}}
1012 struct C c; // expected-error {{refers to a typedef}}
1013
B()1014 B::B() {} // expected-error {{requires a type specifier}}
A()1015 B::A() {} // ok
~C()1016 C::~C() {} // expected-error {{destructor cannot be declared using a typedef 'C' (aka 'const dr298::A') of the class name}}
1017
1018 typedef struct D E; // expected-note {{here}}
1019 struct E {}; // expected-error {{conflicts with typedef}}
1020
1021 struct F {
1022 ~F();
1023 };
1024 typedef const F G;
~F()1025 G::~F() {} // ok
1026 }
1027
1028 namespace dr299 { // dr299: yes c++11
1029 struct S {
1030 operator int();
1031 };
1032 struct T {
1033 operator int(); // expected-note {{}}
1034 operator unsigned short(); // expected-note {{}}
1035 };
1036 // FIXME: should this apply to c++98 mode?
1037 int *p = new int[S()]; // expected-error 0-1{{extension}}
1038 int *q = new int[T()]; // expected-error {{ambiguous}}
1039 }
1040