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
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&) { // expected-note {{for type 'const dr308::A &'}}
174      // unreachable
175    } catch (const B&) { // expected-warning {{exception of type 'const dr308::B &' will be caught by earlier handler}}
176      // get here instead
177    }
178  }
179}
180
181// dr309: dup 485
182
183namespace dr311 { // dr311: yes
184  namespace X { namespace Y {} }
185  namespace X::Y {}
186#if __cplusplus <= 201402L
187  // expected-error@-2 {{define each namespace separately}}
188#endif
189  namespace X {
190    namespace X::Y {}
191#if __cplusplus <= 201402L
192  // expected-error@-2 {{define each namespace separately}}
193#endif
194  }
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 { // FIXME 314: 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}}
332  int *i = &++s.n; // expected-error {{address of bit-field}}
333}
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
376namespace dr332 { // dr332: dup 577
377  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 { // FIXME 343: 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 0-4{{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#elif __cplusplus <= 201402L
719  // expected-error@-10 {{must be cast}}
720  // ok
721  // expected-error@-10 {{does not match}}
722  // expected-error@-10 {{does not match}}
723#else
724  // expected-error@-15 {{conversion from 'int' to 'int *' is not allowed}}
725  // ok
726  // expected-error@-15 {{'float *' is not implicitly convertible to 'int *'}}
727  // expected-error@-15 {{'int dr354::S::*' is not implicitly convertible to 'int *'}}
728#endif
729
730  template<int*> int both();
731  template<int> int both();
732  int b0 = both<0>();
733  int b1 = both<(int*)0>();
734#if __cplusplus < 201103L
735  // expected-error@-2 {{no matching function}}
736  // expected-note@-6 {{candidate}}
737  // expected-note@-6 {{candidate}}
738#endif
739
740  template<int S::*> struct ptr_mem {}; // expected-note 0-4{{here}}
741  ptr_mem<0> m0;
742  ptr_mem<(int S::*)0> m1;
743  ptr_mem<(float S::*)0> m2;
744  ptr_mem<(int *)0> m3;
745#if __cplusplus < 201103L
746  // expected-error@-5 {{cannot be converted}}
747  // expected-error@-5 {{is not a pointer to member constant}}
748  // expected-error@-5 {{cannot be converted}}
749  // expected-error@-5 {{cannot be converted}}
750#elif __cplusplus <= 201402L
751  // expected-error@-10 {{must be cast}}
752  // ok
753  // expected-error@-10 {{does not match}}
754  // expected-error@-10 {{does not match}}
755#else
756  // expected-error@-15 {{conversion from 'int' to 'int dr354::S::*' is not allowed}}
757  // ok
758  // expected-error@-15 {{'float dr354::S::*' is not implicitly convertible to 'int dr354::S::*'}}
759  // expected-error@-15 {{'int *' is not implicitly convertible to 'int dr354::S::*'}}
760#endif
761}
762
763struct dr355_S; // dr355: yes
764struct ::dr355_S {}; // expected-warning {{extra qualification}}
765namespace dr355 { struct ::dr355_S s; }
766
767// dr356: na
768
769namespace dr357 { // dr357: yes
770  template<typename T> struct A {
771    void f() const; // expected-note {{const qualified}}
772  };
773  template<typename T> void A<T>::f() {} // expected-error {{does not match}}
774
775  struct B {
776    template<typename T> void f();
777  };
778  template<typename T> void B::f() const {} // expected-error {{does not match}}
779}
780
781namespace dr358 { // dr358: yes
782  extern "C" void dr358_f();
783  namespace N {
784    int var;
785    extern "C" void dr358_f() { var = 10; }
786  }
787}
788
789namespace dr359 { // dr359: yes
790  // Note, the example in the DR is wrong; it doesn't contain an anonymous
791  // union.
792  struct E {
793    union {
794      struct {
795        int x;
796      } s;
797    } v;
798
799    union {
800      struct { // expected-error {{extension}}
801        int x;
802      } s;
803
804      struct S { // expected-error {{types cannot be declared in an anonymous union}}
805        int x;
806      } t;
807
808      union { // expected-error {{extension}}
809        int u;
810      };
811    };
812  };
813}
814
815// dr362: na
816// dr363: na
817
818namespace dr364 { // dr364: yes
819  struct S {
820    static void f(int);
821    void f(char);
822  };
823
824  void g() {
825    S::f('a'); // expected-error {{call to non-static}}
826    S::f(0);
827  }
828}
829
830#if "foo" // expected-error {{invalid token}} dr366: yes
831#endif
832
833namespace dr367 { // dr367: yes
834  // FIXME: These diagnostics are terrible. Don't diagnose an ill-formed global
835  // array as being a VLA!
836  int a[true ? throw 0 : 4]; // expected-error 2{{variable length array}}
837  int b[true ? 4 : throw 0];
838  int c[true ? *new int : 4]; // expected-error 2{{variable length array}}
839  int d[true ? 4 : *new int];
840#if __cplusplus < 201103L
841  // expected-error@-4 {{variable length array}} expected-error@-4 {{constant expression}}
842  // expected-error@-3 {{variable length array}} expected-error@-3 {{constant expression}}
843#endif
844}
845
846namespace dr368 { // dr368: yes
847  template<typename T, T> struct S {}; // expected-note {{here}}
848  template<typename T> int f(S<T, T()> *); // expected-error {{function type}}
849  //template<typename T> int g(S<T, (T())> *); // FIXME: crashes clang
850  template<typename T> int g(S<T, true ? T() : T()> *); // expected-note {{cannot have type 'dr368::X'}}
851  struct X {};
852  int n = g<X>(0); // expected-error {{no matching}}
853}
854
855// dr370: na
856
857namespace dr372 { // dr372: no
858  namespace example1 {
859    template<typename T> struct X {
860    protected:
861      typedef T Type; // expected-note 2{{protected}}
862    };
863    template<typename T> struct Y {};
864
865    // FIXME: These two are valid; deriving from T1<T> gives Z1 access to
866    // the protected member T1<T>::Type.
867    template<typename T,
868             template<typename> class T1,
869             template<typename> class T2> struct Z1 :
870      T1<T>,
871      T2<typename T1<T>::Type> {}; // expected-error {{protected}}
872
873    template<typename T,
874             template<typename> class T1,
875             template<typename> class T2> struct Z2 :
876      T2<typename T1<T>::Type>, // expected-error {{protected}}
877      T1<T> {};
878
879    Z1<int, X, Y> z1; // expected-note {{instantiation of}}
880    Z2<int, X, Y> z2; // expected-note {{instantiation of}}
881  }
882
883  namespace example2 {
884    struct X {
885    private:
886      typedef int Type; // expected-note {{private}}
887    };
888    template<typename T> struct A {
889      typename T::Type t; // expected-error {{private}}
890    };
891    A<X> ax; // expected-note {{instantiation of}}
892  }
893
894  namespace example3 {
895    struct A {
896    protected:
897      typedef int N; // expected-note 2{{protected}}
898    };
899
900    template<typename T> struct B {};
901    template<typename U> struct C : U, B<typename U::N> {}; // expected-error {{protected}}
902    template<typename U> struct D : B<typename U::N>, U {}; // expected-error {{protected}}
903
904    C<A> x; // expected-note {{instantiation of}}
905    D<A> y; // expected-note {{instantiation of}}
906  }
907
908  namespace example4 {
909    class A {
910      class B {};
911      friend class X;
912    };
913
914    struct X : A::B {
915      A::B mx;
916      class Y {
917        A::B my;
918      };
919    };
920  }
921}
922
923namespace dr373 { // dr373: no
924  // FIXME: This is valid.
925  namespace X { int dr373; } // expected-note 2{{here}}
926  struct dr373 { // expected-note {{here}}
927    void f() {
928      using namespace dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
929      int k = dr373; // expected-error {{does not refer to a value}}
930
931      namespace Y = dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
932      k = Y::dr373;
933    }
934  };
935}
936
937namespace dr374 { // dr374: yes c++11
938  namespace N {
939    template<typename T> void f();
940    template<typename T> struct A { void f(); };
941  }
942  template<> void N::f<char>() {}
943  template<> void N::A<char>::f() {}
944  template<> struct N::A<int> {};
945#if __cplusplus < 201103L
946  // expected-error@-4 {{extension}} expected-note@-7 {{here}}
947  // expected-error@-4 {{extension}} expected-note@-7 {{here}}
948  // expected-error@-4 {{extension}} expected-note@-8 {{here}}
949#endif
950}
951
952// dr375: dup 345
953// dr376: na
954
955namespace dr377 { // dr377: yes
956  enum E { // expected-error {{enumeration values exceed range of largest integer}}
957    a = -__LONG_LONG_MAX__ - 1, // expected-error 0-1{{extension}}
958    b = 2 * (unsigned long long)__LONG_LONG_MAX__ // expected-error 0-2{{extension}}
959  };
960}
961
962// dr378: dup 276
963// dr379: na
964
965namespace dr381 { // dr381: yes
966  struct A {
967    int a;
968  };
969  struct B : virtual A {};
970  struct C : B {};
971  struct D : B {};
972  struct E : public C, public D {};
973  struct F : public A {};
974  void f() {
975    E e;
976    e.B::a = 0; // expected-error {{ambiguous conversion}}
977    F f;
978    f.A::a = 1;
979  }
980}
981
982namespace dr382 { // dr382: yes c++11
983  // FIXME: Should we allow this in C++98 mode?
984  struct A { typedef int T; };
985  typename A::T t;
986  typename dr382::A a;
987#if __cplusplus < 201103L
988  // expected-error@-3 {{occurs outside of a template}}
989  // expected-error@-3 {{occurs outside of a template}}
990#endif
991  typename A b; // expected-error {{expected a qualified name}}
992}
993
994namespace dr383 { // dr383: yes
995  struct A { A &operator=(const A&); };
996  struct B { ~B(); };
997  union C { C &operator=(const C&); };
998  union D { ~D(); };
999  int check[(__is_pod(A) || __is_pod(B) || __is_pod(C) || __is_pod(D)) ? -1 : 1];
1000}
1001
1002namespace dr384 { // dr384: yes
1003  namespace N1 {
1004    template<typename T> struct Base {};
1005    template<typename T> struct X {
1006      struct Y : public Base<T> {
1007        Y operator+(int) const;
1008      };
1009      Y f(unsigned i) { return Y() + i; }
1010    };
1011  }
1012
1013  namespace N2 {
1014    struct Z {};
1015    template<typename T> int *operator+(T, unsigned);
1016  }
1017
1018  int main() {
1019    N1::X<N2::Z> v;
1020    v.f(0);
1021  }
1022}
1023
1024namespace dr385 { // dr385: yes
1025  struct A { protected: void f(); };
1026  struct B : A { using A::f; };
1027  struct C : A { void g(B b) { b.f(); } };
1028  void h(B b) { b.f(); }
1029
1030  struct D { int n; }; // expected-note {{member}}
1031  struct E : protected D {}; // expected-note 2{{protected}}
1032  struct F : E { friend int i(E); };
1033  int i(E e) { return e.n; } // expected-error {{protected base}} expected-error {{protected member}}
1034}
1035
1036namespace dr387 { // dr387: yes
1037  namespace old {
1038    template<typename T> class number {
1039      number(int); // expected-note 2{{here}}
1040      friend number gcd(number &x, number &y) {}
1041    };
1042
1043    void g() {
1044      number<double> a(3), b(4); // expected-error 2{{private}}
1045      a = gcd(a, b);
1046      b = gcd(3, 4); // expected-error {{undeclared}}
1047    }
1048  }
1049
1050  namespace newer {
1051    template <typename T> class number {
1052    public:
1053      number(int);
1054      friend number gcd(number x, number y) { return 0; }
1055    };
1056
1057    void g() {
1058      number<double> a(3), b(4);
1059      a = gcd(a, b);
1060      b = gcd(3, 4); // expected-error {{undeclared}}
1061    }
1062  }
1063}
1064
1065// FIXME: dr388 needs codegen test
1066
1067namespace dr389 { // dr389: no
1068  struct S {
1069    typedef struct {} A;
1070    typedef enum {} B;
1071    typedef struct {} const C; // expected-note 0-2{{here}}
1072    typedef enum {} const D; // expected-note 0-1{{here}}
1073  };
1074  template<typename> struct T {};
1075
1076  struct WithLinkage1 {};
1077  enum WithLinkage2 {};
1078  typedef struct {} *WithLinkage3a, WithLinkage3b;
1079  typedef enum {} WithLinkage4a, *WithLinkage4b;
1080  typedef S::A WithLinkage5;
1081  typedef const S::B WithLinkage6;
1082  typedef int WithLinkage7;
1083  typedef void (*WithLinkage8)(WithLinkage2 WithLinkage1::*, WithLinkage5 *);
1084  typedef T<WithLinkage5> WithLinkage9;
1085
1086  typedef struct {} *WithoutLinkage1; // expected-note 0-1{{here}}
1087  typedef enum {} const WithoutLinkage2; // expected-note 0-1{{here}}
1088  // These two types don't have linkage even though they are externally visible
1089  // and the ODR requires them to be merged across TUs.
1090  typedef S::C WithoutLinkage3;
1091  typedef S::D WithoutLinkage4;
1092  typedef void (*WithoutLinkage5)(int (WithoutLinkage3::*)(char));
1093
1094#if __cplusplus >= 201103L
1095  // This has linkage even though its template argument does not.
1096  // FIXME: This is probably a defect.
1097  typedef T<WithoutLinkage1> WithLinkage10;
1098#else
1099  typedef int WithLinkage10; // dummy
1100
1101  typedef T<WithLinkage1> GoodArg1;
1102  typedef T<WithLinkage2> GoodArg2;
1103  typedef T<WithLinkage3a> GoodArg3a;
1104  typedef T<WithLinkage3b> GoodArg3b;
1105  typedef T<WithLinkage4a> GoodArg4a;
1106  typedef T<WithLinkage4b> GoodArg4b;
1107  typedef T<WithLinkage5> GoodArg5;
1108  typedef T<WithLinkage6> GoodArg6;
1109  typedef T<WithLinkage7> GoodArg7;
1110  typedef T<WithLinkage8> GoodArg8;
1111  typedef T<WithLinkage9> GoodArg9;
1112
1113  typedef T<WithoutLinkage1> BadArg1; // expected-error{{template argument uses}}
1114  typedef T<WithoutLinkage2> BadArg2; // expected-error{{template argument uses}}
1115  typedef T<WithoutLinkage3> BadArg3; // expected-error{{template argument uses}}
1116  typedef T<WithoutLinkage4> BadArg4; // expected-error{{template argument uses}}
1117  typedef T<WithoutLinkage5> BadArg5; // expected-error{{template argument uses}}
1118#endif
1119
1120  extern WithLinkage1 withLinkage1;
1121  extern WithLinkage2 withLinkage2;
1122  extern WithLinkage3a withLinkage3a;
1123  extern WithLinkage3b withLinkage3b;
1124  extern WithLinkage4a withLinkage4a;
1125  extern WithLinkage4b withLinkage4b;
1126  extern WithLinkage5 withLinkage5;
1127  extern WithLinkage6 withLinkage6;
1128  extern WithLinkage7 withLinkage7;
1129  extern WithLinkage8 withLinkage8;
1130  extern WithLinkage9 withLinkage9;
1131  extern WithLinkage10 withLinkage10;
1132
1133  // FIXME: These are all ill-formed.
1134  extern WithoutLinkage1 withoutLinkage1;
1135  extern WithoutLinkage2 withoutLinkage2;
1136  extern WithoutLinkage3 withoutLinkage3;
1137  extern WithoutLinkage4 withoutLinkage4;
1138  extern WithoutLinkage5 withoutLinkage5;
1139
1140  // OK, extern "C".
1141  extern "C" {
1142    extern WithoutLinkage1 dr389_withoutLinkage1;
1143    extern WithoutLinkage2 dr389_withoutLinkage2;
1144    extern WithoutLinkage3 dr389_withoutLinkage3;
1145    extern WithoutLinkage4 dr389_withoutLinkage4;
1146    extern WithoutLinkage5 dr389_withoutLinkage5;
1147  }
1148
1149  // OK, defined.
1150  WithoutLinkage1 withoutLinkageDef1;
1151  WithoutLinkage2 withoutLinkageDef2 = WithoutLinkage2();
1152  WithoutLinkage3 withoutLinkageDef3 = {};
1153  WithoutLinkage4 withoutLinkageDef4 = WithoutLinkage4();
1154  WithoutLinkage5 withoutLinkageDef5;
1155
1156  void use(const void *);
1157  void use_all() {
1158    use(&withLinkage1); use(&withLinkage2); use(&withLinkage3a); use(&withLinkage3b);
1159    use(&withLinkage4a); use(&withLinkage4b); use(&withLinkage5); use(&withLinkage6);
1160    use(&withLinkage7); use(&withLinkage8); use(&withLinkage9); use(&withLinkage10);
1161
1162    use(&withoutLinkage1); use(&withoutLinkage2); use(&withoutLinkage3);
1163    use(&withoutLinkage4); use(&withoutLinkage5);
1164
1165    use(&dr389_withoutLinkage1); use(&dr389_withoutLinkage2);
1166    use(&dr389_withoutLinkage3); use(&dr389_withoutLinkage4);
1167    use(&dr389_withoutLinkage5);
1168
1169    use(&withoutLinkageDef1); use(&withoutLinkageDef2); use(&withoutLinkageDef3);
1170    use(&withoutLinkageDef4); use(&withoutLinkageDef5);
1171  }
1172
1173  void local() {
1174    // FIXME: This is ill-formed.
1175    extern WithoutLinkage1 withoutLinkageLocal;
1176  }
1177}
1178
1179namespace dr390 { // dr390: yes
1180  template<typename T>
1181  struct A {
1182    A() { f(); } // expected-warning {{call to pure virt}}
1183    virtual void f() = 0; // expected-note {{here}}
1184    virtual ~A() = 0;
1185  };
1186  template<typename T> A<T>::~A() { T::error; } // expected-error {{cannot be used prior to}}
1187  template<typename T> void A<T>::f() { T::error; } // ok, not odr-used
1188  struct B : A<int> { // expected-note 2{{in instantiation of}}
1189    void f() {}
1190  } b;
1191}
1192
1193namespace dr391 { // dr391: yes c++11
1194  // FIXME: Should this apply to C++98 too?
1195  class A { A(const A&); }; // expected-note 0-1{{here}}
1196  A fa();
1197  const A &a = fa();
1198#if __cplusplus < 201103L
1199  // expected-error@-2 {{C++98 requires an accessible copy constructor}}
1200#endif
1201
1202  struct B { B(const B&) = delete; }; // expected-error 0-1{{extension}} expected-note 0-1{{here}}
1203  B fb();
1204  const B &b = fb();
1205#if __cplusplus < 201103L
1206  // expected-error@-2 {{deleted}}
1207#endif
1208
1209  template<typename T>
1210  struct C {
1211    C(const C&) { T::error; }
1212  };
1213  C<int> fc();
1214  const C<int> &c = fc();
1215}
1216
1217// dr392 FIXME write codegen test
1218// dr394: na
1219
1220namespace dr395 { // dr395: yes
1221  struct S {
1222    template <typename T, int N>(&operator T())[N]; // expected-error {{cannot specify any part of a return type}}
1223    template <typename T, int N> operator(T (&)[N])(); // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error +{{}}
1224    template <typename T> operator T *() const { return 0; }
1225    template <typename T, typename U> operator T U::*() const { return 0; }
1226    template <typename T, typename U> operator T (U::*)()() const { return 0; } // expected-error +{{}}
1227  };
1228
1229  struct null1_t {
1230    template <class T, class U> struct ptr_mem_fun_t {
1231      typedef T (U::*type)();
1232    };
1233
1234    template <class T, class U>
1235    operator typename ptr_mem_fun_t<T, U>::type() const { // expected-note {{couldn't infer}}
1236      return 0;
1237    }
1238  } null1;
1239  int (S::*p)() = null1; // expected-error {{no viable conversion}}
1240
1241  template <typename T> using id = T; // expected-error 0-1{{extension}}
1242
1243  struct T {
1244    template <typename T, int N> operator id<T[N]> &();
1245    template <typename T, typename U> operator id<T (U::*)()>() const;
1246  };
1247
1248  struct null2_t {
1249    template<class T, class U> using ptr_mem_fun_t = T (U::*)(); // expected-error 0-1{{extension}}
1250    template<class T, class U> operator ptr_mem_fun_t<T, U>() const { return 0; };
1251  } null2;
1252  int (S::*q)() = null2;
1253}
1254
1255namespace dr396 { // dr396: yes
1256  void f() {
1257    auto int a(); // expected-error {{storage class on function}}
1258    int (i); // expected-note {{previous}}
1259    auto int (i); // expected-error {{redefinition}}
1260#if __cplusplus >= 201103L
1261  // expected-error@-4 {{'auto' storage class}} expected-error@-2 {{'auto' storage class}}
1262#endif
1263  }
1264}
1265
1266// dr397: sup 1823
1267
1268namespace dr398 { // dr398: yes
1269  namespace example1 {
1270    struct S {
1271      static int const I = 42;
1272    };
1273    template <int N> struct X {};
1274    template <typename T> void f(X<T::I> *) {}
1275    template <typename T> void f(X<T::J> *) {}
1276    void foo() { f<S>(0); }
1277  }
1278
1279  namespace example2 {
1280    template <int I> struct X {};
1281    template <template <class T> class> struct Z {};
1282    template <class T> void f(typename T::Y *) {} // expected-note 2{{substitution failure}}
1283    template <class T> void g(X<T::N> *) {} // expected-note {{substitution failure}}
1284    template <class T> void h(Z<T::template TT> *) {} // expected-note {{substitution failure}}
1285    struct A {};
1286    struct B {
1287      int Y;
1288    };
1289    struct C {
1290      typedef int N;
1291    };
1292    struct D {
1293      typedef int TT;
1294    };
1295
1296    void test() {
1297      f<A>(0); // expected-error {{no matching function}}
1298      f<B>(0); // expected-error {{no matching function}}
1299      g<C>(0); // expected-error {{no matching function}}
1300      h<D>(0); // expected-error {{no matching function}}
1301    }
1302  }
1303}
1304