Clang Project

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