blob: 59deacae3a67806dabb31c1787338bf6dab7a840 [file] [log] [blame]
Stephen Hines651f13c2014-04-23 16:59:28 -07001// 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
Stephen Hines176edba2014-12-01 14:53:08 -08003// 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
Stephen Hines651f13c2014-04-23 16:59:28 -07005
6namespace dr300 { // dr300: yes
7 template<typename R, typename A> void f(R (&)(A)) {}
8 int g(int);
9 void h() { f(g); }
10}
11
12namespace dr301 { // dr301: yes
13 // see also dr38
14 struct S;
15 template<typename T> void operator+(T, T);
16 void operator-(S, S);
17
18 void f() {
19 bool a = (void(*)(S, S))operator+<S> <
20 (void(*)(S, S))operator+<S>;
21 bool b = (void(*)(S, S))operator- <
22 (void(*)(S, S))operator-;
23 bool c = (void(*)(S, S))operator+ <
24 (void(*)(S, S))operator-; // expected-error {{expected '>'}}
25 }
26
27 template<typename T> void f() {
28 typename T::template operator+<int> a; // expected-error {{typename specifier refers to a non-type template}} expected-error +{{}}
29 // FIXME: This shouldn't say (null).
30 class T::template operator+<int> b; // expected-error {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}}
31 enum T::template operator+<int> c; // expected-error {{expected identifier}} expected-error {{does not declare anything}}
32 enum T::template operator+<int>::E d; // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}} expected-error {{forward reference}}
33 enum T::template X<int>::E e;
34 T::template operator+<int>::foobar(); // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}}
35 T::template operator+<int>(0); // ok
36 }
37
38 template<typename T> class operator&<T*> {}; // expected-error +{{}}
39 template<typename T> class T::operator& {}; // expected-error +{{}}
40 template<typename T> class S::operator&<T*> {}; // expected-error +{{}}
41}
42
43namespace dr302 { // dr302: yes
44 struct A { A(); ~A(); };
45#if __cplusplus < 201103L
46 struct B { // expected-error {{implicit default constructor for 'dr302::B' must explicitly initialize the const member 'n'}}
47 const int n; // expected-note {{declared here}}
48 A a;
49 } b = B(); // expected-note {{first required here}}
50 // Trivial default constructor C::C() is not called here.
51 struct C {
52 const int n;
53 } c = C();
54#else
55 struct B {
56 const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
57 A a;
58 } b = B(); // expected-error {{call to implicitly-deleted default constructor}}
59 // C::C() is called here, because even though it's trivial, it's deleted.
60 struct C {
61 const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
62 } c = C(); // expected-error {{call to implicitly-deleted default constructor}}
63 struct D {
64 const int n = 0;
65 } d = D();
66#endif
67}
68
69// dr303: na
70
71namespace dr304 { // dr304: yes
72 typedef int &a;
73 int n = a(); // expected-error {{requires an initializer}}
74
75 struct S { int &b; };
76 int m = S().b;
77#if __cplusplus < 201103L
78 // expected-error@-3 {{requires an initializer}}
79 // expected-note@-3 {{in value-initialization}}
80#else
81 // expected-error@-5 {{deleted}}
82 // expected-note@-7 {{reference}}
83#endif
84}
85
86namespace dr305 { // dr305: no
87 struct A {
88 typedef A C;
89 };
90 void f(A *a) {
91 struct A {};
92 a->~A();
93 a->~C();
94 }
95 typedef A B;
96 void g(B *b) {
97 b->~B();
98 b->~C();
99 }
100 void h(B *b) {
101 struct B {}; // expected-note {{declared here}}
102 b->~B(); // expected-error {{does not match}}
103 }
104
105 template<typename T> struct X {};
106 void i(X<int>* x) {
107 struct X {};
108 x->~X<int>();
109 x->~X();
110 x->~X<char>(); // expected-error {{no member named}}
111 }
112
113 // FIXME: This appears to be valid (but allowing the nested types might be a
114 // defect).
115 template<typename> struct Nested {
116 template<typename> struct Nested {};
117 };
118 void testNested(Nested<int> n) { n.~Nested<int>(); } // expected-error {{no member named}}
119#if __cplusplus < 201103L
120 // expected-error@-2 {{ambiguous}}
121 // expected-note@-6 {{here}}
122 // expected-note@-6 {{here}}
123#endif
124
125#if __cplusplus >= 201103L
126 struct Y {
127 template<typename T> using T1 = Y;
128 };
129 template<typename T> using T2 = Y;
130 void j(Y *y) {
131 y->~T1<int>();
132 y->~T2<int>();
133 }
134 struct Z {
135 template<typename T> using T2 = T;
136 };
137 void k(Z *z) {
138 // FIXME: This diagnostic is terrible.
139 z->~T1<int>(); // expected-error {{'T1' following the 'template' keyword does not refer to a template}} expected-error +{{}}
140 z->~T2<int>(); // expected-error {{no member named '~int'}}
141 z->~T2<Z>();
142 }
143
144 // FIXME: This is valid.
145 namespace Q {
146 template<typename A> struct R {};
147 }
148 template<typename A> using R = Q::R<int>;
149 void qr(Q::R<int> x) { x.~R<char>(); } // expected-error {{no member named}}
150#endif
151}
152
153namespace dr306 { // dr306: no
154 // FIXME: dup 39
155 // FIXME: This should be accepted.
156 struct A { struct B {}; }; // expected-note 2{{member}}
157 struct C { typedef A::B B; }; // expected-note {{member}}
158 struct D : A, A::B, C {};
159 D::B b; // expected-error {{found in multiple base classes of different types}}
160}
161
162// dr307: na
163
164namespace dr308 { // dr308: yes
165 // This is mostly an ABI library issue.
166 struct A {};
167 struct B : A {};
168 struct C : A {};
169 struct D : B, C {};
170 void f() {
171 try {
172 throw D();
173 } catch (const A&) {
174 // unreachable
175 } catch (const B&) {
176 // get here instead
177 }
178 }
179}
180
181// dr309: dup 485
182
183namespace dr311 { // dr311: yes
184 namespace X { namespace Y {} }
Stephen Hines176edba2014-12-01 14:53:08 -0800185 namespace X::Y {}
186#if __cplusplus <= 201402L
187 // expected-error@-2 {{define each namespace separately}}
188#endif
Stephen Hines651f13c2014-04-23 16:59:28 -0700189 namespace X {
Stephen Hines176edba2014-12-01 14:53:08 -0800190 namespace X::Y {}
191#if __cplusplus <= 201402L
192 // expected-error@-2 {{define each namespace separately}}
193#endif
Stephen Hines651f13c2014-04-23 16:59:28 -0700194 }
195 // FIXME: The diagnostics here are not very good.
196 namespace ::dr311::X {} // expected-error 2+{{}} // expected-warning {{extra qual}}
197}
198
199// dr312: dup 616
200
201namespace dr313 { // dr313: dup 299 c++11
202 struct A { operator int() const; };
203 int *p = new int[A()];
204#if __cplusplus < 201103L
205 // FIXME: should this be available in c++98 mode? expected-error@-2 {{extension}}
206#endif
207}
208
209namespace dr314 { // dr314: dup 1710
210 template<typename T> struct A {
211 template<typename U> struct B {};
212 };
213 template<typename T> struct C : public A<T>::template B<T> {
214 C() : A<T>::template B<T>() {}
215 };
216}
217
218// dr315: na
219// dr316: sup 1004
220
221namespace dr317 { // dr317: 3.5
222 void f() {} // expected-note {{previous}}
223 inline void f(); // expected-error {{inline declaration of 'f' follows non-inline definition}}
224
225 int g();
226 int n = g();
227 inline int g() { return 0; }
228
229 int h();
230 int m = h();
231 int h() { return 0; } // expected-note {{previous}}
232 inline int h(); // expected-error {{inline declaration of 'h' follows non-inline definition}}
233}
234
235namespace dr318 { // dr318: sup 1310
236 struct A {};
237 struct A::A a;
238}
239
240namespace dr319 { // dr319: no
241 // FIXME: dup dr389
242 // FIXME: We don't have a diagnostic for a name with linkage
243 // having a type without linkage.
244 typedef struct {
245 int i;
246 } *ps;
247 extern "C" void f(ps);
248 void g(ps); // FIXME: ill-formed, type 'ps' has no linkage
249
250 static enum { e } a1;
251 enum { e2 } a2; // FIXME: ill-formed, enum type has no linkage
252
253 enum { n1 = 1u };
254 typedef int (*pa)[n1];
255 pa parr; // ok, type has linkage despite using 'n1'
256
257 template<typename> struct X {};
258
259 void f() {
260 struct A { int n; };
261 extern A a; // FIXME: ill-formed
262 X<A> xa;
263
264 typedef A B;
265 extern B b; // FIXME: ill-formed
266 X<B> xb;
267
268 const int n = 1;
269 typedef int (*C)[n];
270 extern C c; // ok
271 X<C> xc;
272 }
273#if __cplusplus < 201103L
274 // expected-error@-12 {{uses local type 'A'}}
275 // expected-error@-9 {{uses local type 'A'}}
276#endif
277}
278
279namespace dr320 { // dr320: yes
280#if __cplusplus >= 201103L
281 struct X {
282 constexpr X() {}
283 constexpr X(const X &x) : copies(x.copies + 1) {}
284 unsigned copies = 0;
285 };
286 constexpr X f(X x) { return x; }
287 constexpr unsigned g(X x) { return x.copies; }
288 static_assert(f(X()).copies == g(X()) + 1, "expected one extra copy for return value");
289#endif
290}
291
292namespace dr321 { // dr321: dup 557
293 namespace N {
294 template<int> struct A {
295 template<int> struct B;
296 };
297 template<> template<> struct A<0>::B<0>;
298 void f(A<0>::B<0>);
299 }
300 template<> template<> struct N::A<0>::B<0> {};
301
302 template<typename T> void g(T t) { f(t); }
303 template void g(N::A<0>::B<0>);
304
305 namespace N {
306 template<typename> struct I { friend bool operator==(const I&, const I&); };
307 }
308 N::I<int> i, j;
309 bool x = i == j;
310}
311
312namespace dr322 { // dr322: yes
313 struct A {
314 template<typename T> operator T&();
315 } a;
316 int &r = static_cast<int&>(a);
317 int &s = a;
318}
319
320// dr323: no
321
322namespace dr324 { // dr324: yes
323 struct S { int n : 1; } s; // expected-note 3{{bit-field is declared here}}
324 int &a = s.n; // expected-error {{non-const reference cannot bind to bit-field}}
325 int *b = &s.n; // expected-error {{address of bit-field}}
326 int &c = (s.n = 0); // expected-error {{non-const reference cannot bind to bit-field}}
327 int *d = &(s.n = 0); // expected-error {{address of bit-field}}
328 int &e = true ? s.n : s.n; // expected-error {{non-const reference cannot bind to bit-field}}
329 int *f = &(true ? s.n : s.n); // expected-error {{address of bit-field}}
330 int &g = (void(), s.n); // expected-error {{non-const reference cannot bind to bit-field}}
331 int *h = &(void(), s.n); // expected-error {{address of bit-field}}
Stephen Hines176edba2014-12-01 14:53:08 -0800332 int *i = &++s.n; // expected-error {{address of bit-field}}
Stephen Hines651f13c2014-04-23 16:59:28 -0700333}
334
335namespace dr326 { // dr326: yes
336 struct S {};
337 int test[__is_trivially_constructible(S, const S&) ? 1 : -1];
338}
339
340namespace dr327 { // dr327: dup 538
341 struct A;
342 class A {};
343
344 class B;
345 struct B {};
346}
347
348namespace dr328 { // dr328: yes
349 struct A; // expected-note 3{{forward declaration}}
350 struct B { A a; }; // expected-error {{incomplete}}
351 template<typename> struct C { A a; }; // expected-error {{incomplete}}
352 A *p = new A[0]; // expected-error {{incomplete}}
353}
354
355namespace dr329 { // dr329: 3.5
356 struct B {};
357 template<typename T> struct A : B {
358 friend void f(A a) { g(a); }
359 friend void h(A a) { g(a); } // expected-error {{undeclared}}
360 friend void i(B b) {} // expected-error {{redefinition}} expected-note {{previous}}
361 };
362 A<int> a;
363 A<char> b; // expected-note {{instantiation}}
364
365 void test() {
366 h(a); // expected-note {{instantiation}}
367 }
368}
369
370namespace dr331 { // dr331: yes
371 struct A {
372 A(volatile A&); // expected-note {{candidate}}
373 } const a, b(a); // expected-error {{no matching constructor}}
374}
375
Stephen Hines176edba2014-12-01 14:53:08 -0800376namespace dr332 { // dr332: dup 577
Stephen Hines651f13c2014-04-23 16:59:28 -0700377 void f(volatile void); // expected-error {{'void' as parameter must not have type qualifiers}}
378 void g(const void); // expected-error {{'void' as parameter must not have type qualifiers}}
379 void h(int n, volatile void); // expected-error {{'void' must be the first and only parameter}}
380}
381
382namespace dr333 { // dr333: yes
383 int n = 0;
384 int f(int(n));
385 int g((int(n)));
386 int h = f(g);
387}
388
389namespace dr334 { // dr334: yes
390 template<typename T> void f() {
391 T x;
392 f((x, 123));
393 }
394 struct S {
395 friend S operator,(S, int);
396 friend void f(S);
397 };
398 template void f<S>();
399}
400
401// dr335: no
402
403namespace dr336 { // dr336: yes
404 namespace Pre {
405 template<class T1> class A {
406 template<class T2> class B {
407 template<class T3> void mf1(T3);
408 void mf2();
409 };
410 };
411 template<> template<class X> class A<int>::B {};
412 template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {} // expected-error {{does not match}}
413 template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}}
414 }
415 namespace Post {
416 template<class T1> class A {
417 template<class T2> class B {
418 template<class T3> void mf1(T3);
419 void mf2();
420 };
421 };
422 template<> template<class X> class A<int>::B {
423 template<class T> void mf1(T);
424 };
425 template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {}
426 // FIXME: This diagnostic isn't very good.
427 template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}}
428 }
429}
430
431namespace dr337 { // dr337: yes
432 template<typename T> void f(T (*)[1]);
433 template<typename T> int &f(...);
434
435 struct A { virtual ~A() = 0; };
436 int &r = f<A>(0);
437
438 // FIXME: The language rules here are completely broken. We cannot determine
439 // whether an incomplete type is abstract. See DR1640, which will probably
440 // supersede this one and remove this rule.
441 struct B;
442 int &s = f<B>(0); // expected-error {{of type 'void'}}
443 struct B { virtual ~B() = 0; };
444}
445
446namespace dr339 { // dr339: yes
447 template <int I> struct A { static const int value = I; };
448
449 char xxx(int);
450 char (&xxx(float))[2];
451
452 template<class T> A<sizeof(xxx((T)0))> f(T) {} // expected-note {{candidate}}
453
454 void test() {
455 A<1> a = f(0);
456 A<2> b = f(0.0f);
457 A<3> c = f("foo"); // expected-error {{no matching function}}
458 }
459
460
461 char f(int);
462 int f(...);
463
464 template <class T> struct conv_int {
465 static const bool value = sizeof(f(T())) == 1;
466 };
467
468 template <class T> bool conv_int2(A<sizeof(f(T()))> p);
469
470 template<typename T> A<sizeof(f(T()))> make_A();
471
472 int a[conv_int<char>::value ? 1 : -1];
473 bool b = conv_int2<char>(A<1>());
474 A<1> c = make_A<char>();
475}
476
477namespace dr340 { // dr340: yes
478 struct A { A(int); };
479 struct B { B(A, A, int); };
480 int x, y;
481 B b(A(x), A(y), 3);
482}
483
484namespace dr341 { // dr341: sup 1708
485 namespace A {
486 int n;
487 extern "C" int &dr341_a = n; // expected-note {{previous}} expected-note {{declared with C language linkage here}}
488 }
489 namespace B {
490 extern "C" int &dr341_a = dr341_a; // expected-error {{redefinition}}
491 }
492 extern "C" void dr341_b(); // expected-note {{declared with C language linkage here}}
493}
494int dr341_a; // expected-error {{declaration of 'dr341_a' in global scope conflicts with declaration with C language linkage}}
495int dr341_b; // expected-error {{declaration of 'dr341_b' in global scope conflicts with declaration with C language linkage}}
496int dr341_c; // expected-note {{declared in global scope here}}
497int dr341_d; // expected-note {{declared in global scope here}}
498namespace dr341 {
499 extern "C" int dr341_c; // expected-error {{declaration of 'dr341_c' with C language linkage conflicts with declaration in global scope}}
500 extern "C" void dr341_d(); // expected-error {{declaration of 'dr341_d' with C language linkage conflicts with declaration in global scope}}
501
502 namespace A { extern "C" int dr341_e; } // expected-note {{previous}}
503 namespace B { extern "C" void dr341_e(); } // expected-error {{redefinition of 'dr341_e' as different kind of symbol}}
504}
505
506// dr342: na
507
508namespace dr343 { // dr343: no
509 // FIXME: dup 1710
510 template<typename T> struct A {
511 template<typename U> struct B {};
512 };
513 // FIXME: In these contexts, the 'template' keyword is optional.
514 template<typename T> struct C : public A<T>::B<T> { // expected-error {{use 'template'}}
515 C() : A<T>::B<T>() {} // expected-error {{use 'template'}}
516 };
517}
518
519namespace dr344 { // dr344: dup 1435
520 struct A { inline virtual ~A(); };
521 struct B { friend A::~A(); };
522}
523
524namespace dr345 { // dr345: yes
525 struct A {
526 struct X {};
527 int X; // expected-note {{here}}
528 };
529 struct B {
530 struct X {};
531 };
532 template <class T> void f(T t) { typename T::X x; } // expected-error {{refers to non-type member 'X'}}
533 void f(A a, B b) {
534 f(b);
535 f(a); // expected-note {{instantiation}}
536 }
537}
538
539// dr346: na
540
541namespace dr347 { // dr347: yes
542 struct base {
543 struct nested;
544 static int n;
545 static void f();
546 void g();
547 };
548
549 struct derived : base {};
550
551 struct derived::nested {}; // expected-error {{no struct named 'nested'}}
552 int derived::n; // expected-error {{no member named 'n'}}
553 void derived::f() {} // expected-error {{does not match any}}
554 void derived::g() {} // expected-error {{does not match any}}
555}
556
557// dr348: na
558
559namespace dr349 { // dr349: no
560 struct A {
561 template <class T> operator T ***() {
562 int ***p = 0;
563 return p; // expected-error {{cannot initialize return object of type 'const int ***' with an lvalue of type 'int ***'}}
564 }
565 };
566
567 // FIXME: This is valid.
568 A a;
569 const int *const *const *p1 = a; // expected-note {{in instantiation of}}
570
571 struct B {
572 template <class T> operator T ***() {
573 const int ***p = 0;
574 return p;
575 }
576 };
577
578 // FIXME: This is invalid.
579 B b;
580 const int *const *const *p2 = b;
581}
582
583// dr351: na
584
585namespace dr352 { // dr352: yes
586 namespace example1 {
587 namespace A {
588 enum E {};
589 template<typename R, typename A> void foo(E, R (*)(A)); // expected-note 2{{couldn't infer template argument 'R'}}
590 }
591
592 template<typename T> void arg(T);
593 template<typename T> int arg(T) = delete; // expected-note {{here}} expected-error 0-1{{extension}}
594
595 void f(A::E e) {
596 foo(e, &arg); // expected-error {{no matching function}}
597
598 using A::foo;
599 foo<int, int>(e, &arg); // expected-error {{deleted}}
600 }
601
602 int arg(int);
603
604 void g(A::E e) {
605 foo(e, &arg); // expected-error {{no matching function}}
606
607 using A::foo;
608 foo<int, int>(e, &arg); // ok, uses non-template
609 }
610 }
611
612 namespace contexts {
613 template<int I> void f1(int (&)[I]);
614 template<int I> void f2(int (&)[I+1]); // expected-note {{couldn't infer}}
615 template<int I> void f3(int (&)[I+1], int (&)[I]);
616 void f() {
617 int a[4];
618 int b[3];
619 f1(a);
620 f2(a); // expected-error {{no matching function}}
621 f3(a, b);
622 }
623
624 template<int I> struct S {};
625 template<int I> void g1(S<I>);
626 template<int I> void g2(S<I+1>); // expected-note {{couldn't infer}}
627 template<int I> void g3(S<I+1>, S<I>);
628 void g() {
629 S<4> a;
630 S<3> b;
631 g1(a);
632 g2(a); // expected-error {{no matching function}}
633 g3(a, b);
634 }
635
636 template<typename T> void h1(T = 0); // expected-note {{couldn't infer}}
637 template<typename T> void h2(T, T = 0);
638 void h() {
639 h1(); // expected-error {{no matching function}}
640 h1(0);
641 h1<int>();
642 h2(0);
643 }
644
645 template<typename T> int tmpl(T);
646 template<typename R, typename A> void i1(R (*)(A)); // expected-note 3{{couldn't infer}}
647 template<typename R, typename A> void i2(R, A, R (*)(A)); // expected-note {{not viable}}
648 void i() {
649 extern int single(int);
650 i1(single);
651 i2(0, 0, single);
652
653 extern int ambig(float), ambig(int);
654 i1(ambig); // expected-error {{no matching function}}
655 i2(0, 0, ambig);
656
657 extern void no_match(float), no_match(int);
658 i1(no_match); // expected-error {{no matching function}}
659 i2(0, 0, no_match); // expected-error {{no matching function}}
660
661 i1(tmpl); // expected-error {{no matching function}}
662 i2(0, 0, tmpl);
663 }
664 }
665
666 template<typename T> struct is_int;
667 template<> struct is_int<int> {};
668
669 namespace example2 {
670 template<typename T> int f(T (*p)(T)) { is_int<T>(); }
671 int g(int);
672 int g(char);
673 int i = f(g);
674 }
675
676 namespace example3 {
677 template<typename T> int f(T, T (*p)(T)) { is_int<T>(); }
678 int g(int);
679 char g(char);
680 int i = f(1, g);
681 }
682
683 namespace example4 {
684 template <class T> int f(T, T (*p)(T)) { is_int<T>(); }
685 char g(char);
686 template <class T> T g(T);
687 int i = f(1, g);
688 }
689
690 namespace example5 {
691 template<int I> class A {};
692 template<int I> void g(A<I+1>); // expected-note {{couldn't infer}}
693 template<int I> void f(A<I>, A<I+1>);
694 void h(A<1> a1, A<2> a2) {
695 g(a1); // expected-error {{no matching function}}
696 g<0>(a1);
697 f(a1, a2);
698 }
699 }
700}
701
702// dr353 needs an IRGen test.
703
704namespace dr354 { // dr354: yes c++11
705 // FIXME: Should we allow this in C++98 too?
706 struct S {};
707
708 template<int*> struct ptr {}; // expected-note +{{here}}
709 ptr<0> p0;
710 ptr<(int*)0> p1;
711 ptr<(float*)0> p2;
712 ptr<(int S::*)0> p3;
713#if __cplusplus < 201103L
714 // expected-error@-5 {{does not refer to any decl}}
715 // expected-error@-5 {{does not refer to any decl}}
716 // expected-error@-5 {{does not refer to any decl}}
717 // expected-error@-5 {{does not refer to any decl}}
718#else
719 // expected-error@-10 {{must be cast}}
720 // ok
721 // expected-error@-10 {{does not match}}
722 // expected-error@-10 {{does not match}}
723#endif
724
725 template<int*> int both();
726 template<int> int both();
727 int b0 = both<0>();
728 int b1 = both<(int*)0>();
729#if __cplusplus < 201103L
730 // expected-error@-2 {{no matching function}}
731 // expected-note@-6 {{candidate}}
732 // expected-note@-6 {{candidate}}
733#endif
734
735 template<int S::*> struct ptr_mem {}; // expected-note +{{here}}
736 ptr_mem<0> m0;
737 ptr_mem<(int S::*)0> m1;
738 ptr_mem<(float S::*)0> m2;
739 ptr_mem<(int *)0> m3;
740#if __cplusplus < 201103L
741 // expected-error@-5 {{cannot be converted}}
742 // expected-error@-5 {{is not a pointer to member constant}}
743 // expected-error@-5 {{cannot be converted}}
744 // expected-error@-5 {{cannot be converted}}
745#else
746 // expected-error@-10 {{must be cast}}
747 // ok
748 // expected-error@-10 {{does not match}}
749 // expected-error@-10 {{does not match}}
750#endif
751}
752
753struct dr355_S; // dr355: yes
754struct ::dr355_S {}; // expected-warning {{extra qualification}}
755namespace dr355 { struct ::dr355_S s; }
756
757// dr356: na
758
759namespace dr357 { // dr357: yes
760 template<typename T> struct A {
761 void f() const; // expected-note {{const qualified}}
762 };
763 template<typename T> void A<T>::f() {} // expected-error {{does not match}}
764
765 struct B {
766 template<typename T> void f();
767 };
768 template<typename T> void B::f() const {} // expected-error {{does not match}}
769}
770
771namespace dr358 { // dr358: yes
772 extern "C" void dr358_f();
773 namespace N {
774 int var;
775 extern "C" void dr358_f() { var = 10; }
776 }
777}
778
779namespace dr359 { // dr359: yes
780 // Note, the example in the DR is wrong; it doesn't contain an anonymous
781 // union.
782 struct E {
783 union {
784 struct {
785 int x;
786 } s;
787 } v;
788
789 union {
790 struct { // expected-error {{extension}}
791 int x;
792 } s;
793
794 struct S { // expected-error {{types cannot be declared in an anonymous union}}
795 int x;
796 } t;
797
798 union { // expected-error {{extension}}
799 int u;
800 };
801 };
802 };
803}
804
805// dr362: na
806// dr363: na
807
808namespace dr364 { // dr364: yes
809 struct S {
810 static void f(int);
811 void f(char);
812 };
813
814 void g() {
815 S::f('a'); // expected-error {{call to non-static}}
816 S::f(0);
817 }
818}
819
820#if "foo" // expected-error {{invalid token}} dr366: yes
821#endif
822
823namespace dr367 { // dr367: yes
824 // FIXME: These diagnostics are terrible. Don't diagnose an ill-formed global
825 // array as being a VLA!
826 int a[true ? throw 0 : 4]; // expected-error 2{{variable length array}}
827 int b[true ? 4 : throw 0];
828 int c[true ? *new int : 4]; // expected-error 2{{variable length array}}
829 int d[true ? 4 : *new int];
830#if __cplusplus < 201103L
831 // expected-error@-4 {{variable length array}} expected-error@-4 {{constant expression}}
832 // expected-error@-3 {{variable length array}} expected-error@-3 {{constant expression}}
833#endif
834}
835
836namespace dr368 { // dr368: yes
837 template<typename T, T> struct S {}; // expected-note {{here}}
838 template<typename T> int f(S<T, T()> *); // expected-error {{function type}}
839 //template<typename T> int g(S<T, (T())> *); // FIXME: crashes clang
840 template<typename T> int g(S<T, true ? T() : T()> *); // expected-note {{cannot have type 'dr368::X'}}
841 struct X {};
842 int n = g<X>(0); // expected-error {{no matching}}
843}
844
845// dr370: na
846
847namespace dr372 { // dr372: no
848 namespace example1 {
849 template<typename T> struct X {
850 protected:
851 typedef T Type; // expected-note 2{{protected}}
852 };
853 template<typename T> struct Y {};
854
855 // FIXME: These two are valid; deriving from T1<T> gives Z1 access to
856 // the protected member T1<T>::Type.
857 template<typename T,
858 template<typename> class T1,
859 template<typename> class T2> struct Z1 :
860 T1<T>,
861 T2<typename T1<T>::Type> {}; // expected-error {{protected}}
862
863 template<typename T,
864 template<typename> class T1,
865 template<typename> class T2> struct Z2 :
866 T2<typename T1<T>::Type>, // expected-error {{protected}}
867 T1<T> {};
868
869 Z1<int, X, Y> z1; // expected-note {{instantiation of}}
870 Z2<int, X, Y> z2; // expected-note {{instantiation of}}
871 }
872
873 namespace example2 {
874 struct X {
875 private:
876 typedef int Type; // expected-note {{private}}
877 };
878 template<typename T> struct A {
879 typename T::Type t; // expected-error {{private}}
880 };
881 A<X> ax; // expected-note {{instantiation of}}
882 }
883
884 namespace example3 {
885 struct A {
886 protected:
887 typedef int N; // expected-note 2{{protected}}
888 };
889
890 template<typename T> struct B {};
891 template<typename U> struct C : U, B<typename U::N> {}; // expected-error {{protected}}
892 template<typename U> struct D : B<typename U::N>, U {}; // expected-error {{protected}}
893
894 C<A> x; // expected-note {{instantiation of}}
895 D<A> y; // expected-note {{instantiation of}}
896 }
897
898 namespace example4 {
899 class A {
900 class B {};
901 friend class X;
902 };
903
904 struct X : A::B {
905 A::B mx;
906 class Y {
907 A::B my;
908 };
909 };
910 }
911}
912
913namespace dr373 { // dr373: no
914 // FIXME: This is valid.
915 namespace X { int dr373; } // expected-note 2{{here}}
916 struct dr373 { // expected-note {{here}}
917 void f() {
918 using namespace dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
919 int k = dr373; // expected-error {{does not refer to a value}}
920
921 namespace Y = dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
922 k = Y::dr373;
923 }
924 };
925}
926
927namespace dr374 { // dr374: yes c++11
928 namespace N {
929 template<typename T> void f();
930 template<typename T> struct A { void f(); };
931 }
932 template<> void N::f<char>() {}
933 template<> void N::A<char>::f() {}
934 template<> struct N::A<int> {};
935#if __cplusplus < 201103L
936 // expected-error@-4 {{extension}} expected-note@-7 {{here}}
937 // expected-error@-4 {{extension}} expected-note@-7 {{here}}
938 // expected-error@-4 {{extension}} expected-note@-8 {{here}}
939#endif
940}
941
942// dr375: dup 345
943// dr376: na
944
945namespace dr377 { // dr377: yes
946 enum E { // expected-error {{enumeration values exceed range of largest integer}}
947 a = -__LONG_LONG_MAX__ - 1, // expected-error 0-1{{extension}}
948 b = 2 * (unsigned long long)__LONG_LONG_MAX__ // expected-error 0-2{{extension}}
949 };
950}
951
952// dr378: dup 276
953// dr379: na
954
955namespace dr381 { // dr381: yes
956 struct A {
957 int a;
958 };
959 struct B : virtual A {};
960 struct C : B {};
961 struct D : B {};
962 struct E : public C, public D {};
963 struct F : public A {};
964 void f() {
965 E e;
966 e.B::a = 0; // expected-error {{ambiguous conversion}}
967 F f;
968 f.A::a = 1;
969 }
970}
971
972namespace dr382 { // dr382: yes c++11
973 // FIXME: Should we allow this in C++98 mode?
974 struct A { typedef int T; };
975 typename A::T t;
976 typename dr382::A a;
977#if __cplusplus < 201103L
978 // expected-error@-3 {{occurs outside of a template}}
979 // expected-error@-3 {{occurs outside of a template}}
980#endif
981 typename A b; // expected-error {{expected a qualified name}}
982}
983
984namespace dr383 { // dr383: yes
985 struct A { A &operator=(const A&); };
986 struct B { ~B(); };
987 union C { C &operator=(const C&); };
988 union D { ~D(); };
989 int check[(__is_pod(A) || __is_pod(B) || __is_pod(C) || __is_pod(D)) ? -1 : 1];
990}
991
992namespace dr384 { // dr384: yes
993 namespace N1 {
994 template<typename T> struct Base {};
995 template<typename T> struct X {
996 struct Y : public Base<T> {
997 Y operator+(int) const;
998 };
999 Y f(unsigned i) { return Y() + i; }
1000 };
1001 }
1002
1003 namespace N2 {
1004 struct Z {};
1005 template<typename T> int *operator+(T, unsigned);
1006 }
1007
1008 int main() {
1009 N1::X<N2::Z> v;
1010 v.f(0);
1011 }
1012}
1013
1014namespace dr385 { // dr385: yes
1015 struct A { protected: void f(); };
1016 struct B : A { using A::f; };
1017 struct C : A { void g(B b) { b.f(); } };
1018 void h(B b) { b.f(); }
1019
1020 struct D { int n; }; // expected-note {{member}}
1021 struct E : protected D {}; // expected-note 2{{protected}}
1022 struct F : E { friend int i(E); };
1023 int i(E e) { return e.n; } // expected-error {{protected base}} expected-error {{protected member}}
1024}
1025
1026namespace dr387 { // dr387: yes
1027 namespace old {
1028 template<typename T> class number {
1029 number(int); // expected-note 2{{here}}
1030 friend number gcd(number &x, number &y) {}
1031 };
1032
1033 void g() {
1034 number<double> a(3), b(4); // expected-error 2{{private}}
1035 a = gcd(a, b);
1036 b = gcd(3, 4); // expected-error {{undeclared}}
1037 }
1038 }
1039
1040 namespace newer {
1041 template <typename T> class number {
1042 public:
1043 number(int);
1044 friend number gcd(number x, number y) { return 0; }
1045 };
1046
1047 void g() {
1048 number<double> a(3), b(4);
1049 a = gcd(a, b);
1050 b = gcd(3, 4); // expected-error {{undeclared}}
1051 }
1052 }
1053}
1054
1055// FIXME: dr388 needs codegen test
1056
1057namespace dr389 { // dr389: no
1058 struct S {
1059 typedef struct {} A;
1060 typedef enum {} B;
1061 typedef struct {} const C; // expected-note 0-2{{here}}
1062 typedef enum {} const D; // expected-note 0-1{{here}}
1063 };
1064 template<typename> struct T {};
1065
1066 struct WithLinkage1 {};
1067 enum WithLinkage2 {};
1068 typedef struct {} *WithLinkage3a, WithLinkage3b;
1069 typedef enum {} WithLinkage4a, *WithLinkage4b;
1070 typedef S::A WithLinkage5;
1071 typedef const S::B WithLinkage6;
1072 typedef int WithLinkage7;
1073 typedef void (*WithLinkage8)(WithLinkage2 WithLinkage1::*, WithLinkage5 *);
1074 typedef T<WithLinkage5> WithLinkage9;
1075
1076 typedef struct {} *WithoutLinkage1; // expected-note 0-1{{here}}
1077 typedef enum {} const WithoutLinkage2; // expected-note 0-1{{here}}
1078 // These two types don't have linkage even though they are externally visible
1079 // and the ODR requires them to be merged across TUs.
1080 typedef S::C WithoutLinkage3;
1081 typedef S::D WithoutLinkage4;
1082 typedef void (*WithoutLinkage5)(int (WithoutLinkage3::*)(char));
1083
1084#if __cplusplus >= 201103L
1085 // This has linkage even though its template argument does not.
1086 // FIXME: This is probably a defect.
1087 typedef T<WithoutLinkage1> WithLinkage10;
1088#else
1089 typedef int WithLinkage10; // dummy
1090
1091 typedef T<WithLinkage1> GoodArg1;
1092 typedef T<WithLinkage2> GoodArg2;
1093 typedef T<WithLinkage3a> GoodArg3a;
1094 typedef T<WithLinkage3b> GoodArg3b;
1095 typedef T<WithLinkage4a> GoodArg4a;
1096 typedef T<WithLinkage4b> GoodArg4b;
1097 typedef T<WithLinkage5> GoodArg5;
1098 typedef T<WithLinkage6> GoodArg6;
1099 typedef T<WithLinkage7> GoodArg7;
1100 typedef T<WithLinkage8> GoodArg8;
1101 typedef T<WithLinkage9> GoodArg9;
1102
1103 typedef T<WithoutLinkage1> BadArg1; // expected-error{{template argument uses}}
1104 typedef T<WithoutLinkage2> BadArg2; // expected-error{{template argument uses}}
1105 typedef T<WithoutLinkage3> BadArg3; // expected-error{{template argument uses}}
1106 typedef T<WithoutLinkage4> BadArg4; // expected-error{{template argument uses}}
1107 typedef T<WithoutLinkage5> BadArg5; // expected-error{{template argument uses}}
1108#endif
1109
1110 extern WithLinkage1 withLinkage1;
1111 extern WithLinkage2 withLinkage2;
1112 extern WithLinkage3a withLinkage3a;
1113 extern WithLinkage3b withLinkage3b;
1114 extern WithLinkage4a withLinkage4a;
1115 extern WithLinkage4b withLinkage4b;
1116 extern WithLinkage5 withLinkage5;
1117 extern WithLinkage6 withLinkage6;
1118 extern WithLinkage7 withLinkage7;
1119 extern WithLinkage8 withLinkage8;
1120 extern WithLinkage9 withLinkage9;
1121 extern WithLinkage10 withLinkage10;
1122
1123 // FIXME: These are all ill-formed.
1124 extern WithoutLinkage1 withoutLinkage1;
1125 extern WithoutLinkage2 withoutLinkage2;
1126 extern WithoutLinkage3 withoutLinkage3;
1127 extern WithoutLinkage4 withoutLinkage4;
1128 extern WithoutLinkage5 withoutLinkage5;
1129
1130 // OK, extern "C".
1131 extern "C" {
1132 extern WithoutLinkage1 dr389_withoutLinkage1;
1133 extern WithoutLinkage2 dr389_withoutLinkage2;
1134 extern WithoutLinkage3 dr389_withoutLinkage3;
1135 extern WithoutLinkage4 dr389_withoutLinkage4;
1136 extern WithoutLinkage5 dr389_withoutLinkage5;
1137 }
1138
1139 // OK, defined.
1140 WithoutLinkage1 withoutLinkageDef1;
1141 WithoutLinkage2 withoutLinkageDef2 = WithoutLinkage2();
1142 WithoutLinkage3 withoutLinkageDef3 = {};
1143 WithoutLinkage4 withoutLinkageDef4 = WithoutLinkage4();
1144 WithoutLinkage5 withoutLinkageDef5;
1145
1146 void use(const void *);
1147 void use_all() {
1148 use(&withLinkage1); use(&withLinkage2); use(&withLinkage3a); use(&withLinkage3b);
1149 use(&withLinkage4a); use(&withLinkage4b); use(&withLinkage5); use(&withLinkage6);
1150 use(&withLinkage7); use(&withLinkage8); use(&withLinkage9); use(&withLinkage10);
1151
1152 use(&withoutLinkage1); use(&withoutLinkage2); use(&withoutLinkage3);
1153 use(&withoutLinkage4); use(&withoutLinkage5);
1154
1155 use(&dr389_withoutLinkage1); use(&dr389_withoutLinkage2);
1156 use(&dr389_withoutLinkage3); use(&dr389_withoutLinkage4);
1157 use(&dr389_withoutLinkage5);
1158
1159 use(&withoutLinkageDef1); use(&withoutLinkageDef2); use(&withoutLinkageDef3);
1160 use(&withoutLinkageDef4); use(&withoutLinkageDef5);
1161 }
1162
1163 void local() {
1164 // FIXME: This is ill-formed.
1165 extern WithoutLinkage1 withoutLinkageLocal;
1166 }
1167}
1168
1169namespace dr390 { // dr390: yes
1170 template<typename T>
1171 struct A {
1172 A() { f(); } // expected-warning {{call to pure virt}}
1173 virtual void f() = 0; // expected-note {{here}}
1174 virtual ~A() = 0;
1175 };
1176 template<typename T> A<T>::~A() { T::error; } // expected-error {{cannot be used prior to}}
1177 template<typename T> void A<T>::f() { T::error; } // ok, not odr-used
1178 struct B : A<int> { // expected-note 2{{in instantiation of}}
1179 void f() {}
1180 } b;
1181}
1182
1183namespace dr391 { // dr391: yes c++11
1184 // FIXME: Should this apply to C++98 too?
1185 class A { A(const A&); }; // expected-note 0-1{{here}}
1186 A fa();
1187 const A &a = fa();
1188#if __cplusplus < 201103L
1189 // expected-error@-2 {{C++98 requires an accessible copy constructor}}
1190#endif
1191
1192 struct B { B(const B&) = delete; }; // expected-error 0-1{{extension}} expected-note 0-1{{here}}
1193 B fb();
1194 const B &b = fb();
1195#if __cplusplus < 201103L
1196 // expected-error@-2 {{deleted}}
1197#endif
1198
1199 template<typename T>
1200 struct C {
1201 C(const C&) { T::error; }
1202 };
1203 C<int> fc();
1204 const C<int> &c = fc();
1205}
1206
1207// dr392 FIXME write codegen test
1208// dr394: na
1209
1210namespace dr395 { // dr395: yes
1211 struct S {
1212 template <typename T, int N>(&operator T())[N]; // expected-error {{must use a typedef}}
1213 template <typename T, int N> operator(T (&)[N])(); // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error +{{}}
1214 template <typename T> operator T *() const { return 0; }
1215 template <typename T, typename U> operator T U::*() const { return 0; }
1216 template <typename T, typename U> operator T (U::*)()() const { return 0; } // expected-error +{{}}
1217 };
1218
1219 struct null1_t {
1220 template <class T, class U> struct ptr_mem_fun_t {
1221 typedef T (U::*type)();
1222 };
1223
1224 template <class T, class U>
1225 operator typename ptr_mem_fun_t<T, U>::type() const { // expected-note {{couldn't infer}}
1226 return 0;
1227 }
1228 } null1;
1229 int (S::*p)() = null1; // expected-error {{no viable conversion}}
1230
1231 template <typename T> using id = T; // expected-error 0-1{{extension}}
1232
1233 struct T {
1234 template <typename T, int N> operator id<T[N]> &();
1235 template <typename T, typename U> operator id<T (U::*)()>() const;
1236 };
1237
1238 struct null2_t {
1239 template<class T, class U> using ptr_mem_fun_t = T (U::*)(); // expected-error 0-1{{extension}}
1240 template<class T, class U> operator ptr_mem_fun_t<T, U>() const { return 0; };
1241 } null2;
1242 int (S::*q)() = null2;
1243}
1244
1245namespace dr396 { // dr396: yes
1246 void f() {
1247 auto int a(); // expected-error {{storage class on function}}
1248 int (i); // expected-note {{previous}}
1249 auto int (i); // expected-error {{redefinition}}
1250#if __cplusplus >= 201103L
1251 // expected-error@-4 {{'auto' storage class}} expected-error@-2 {{'auto' storage class}}
1252#endif
1253 }
1254}
1255
1256// dr397: sup 1823
1257
1258namespace dr398 { // dr398: yes
1259 namespace example1 {
1260 struct S {
1261 static int const I = 42;
1262 };
1263 template <int N> struct X {};
1264 template <typename T> void f(X<T::I> *) {}
1265 template <typename T> void f(X<T::J> *) {}
1266 void foo() { f<S>(0); }
1267 }
1268
1269 namespace example2 {
1270 template <int I> struct X {};
1271 template <template <class T> class> struct Z {};
1272 template <class T> void f(typename T::Y *) {} // expected-note 2{{substitution failure}}
1273 template <class T> void g(X<T::N> *) {} // expected-note {{substitution failure}}
1274 template <class T> void h(Z<T::template TT> *) {} // expected-note {{substitution failure}}
1275 struct A {};
1276 struct B {
1277 int Y;
1278 };
1279 struct C {
1280 typedef int N;
1281 };
1282 struct D {
1283 typedef int TT;
1284 };
1285
1286 void test() {
1287 f<A>(0); // expected-error {{no matching function}}
1288 f<B>(0); // expected-error {{no matching function}}
1289 g<C>(0); // expected-error {{no matching function}}
1290 h<D>(0); // expected-error {{no matching function}}
1291 }
1292 }
1293}