]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaTemplate/dependent-template-recover.cpp
Vendor import of clang trunk r305145:
[FreeBSD/FreeBSD.git] / test / SemaTemplate / dependent-template-recover.cpp
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 template<typename T, typename U, int N>
3 struct X {
4   void f(T* t) {
5     t->f0<U>(); // expected-error{{use 'template' keyword to treat 'f0' as a dependent template name}}
6     t->f0<int>(); // expected-error{{use 'template' keyword to treat 'f0' as a dependent template name}}
7
8     t->operator+<U const, 1>(); // expected-error{{use 'template' keyword to treat 'operator +' as a dependent template name}}
9     t->f1<int const, 2>(); // expected-error{{use 'template' keyword to treat 'f1' as a dependent template name}}
10
11     T::getAs<U>(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}}
12     t->T::getAs<U>(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}}
13
14     // FIXME: We can't recover from these yet
15     (*t).f2<N>(); // expected-error{{expected expression}}
16     (*t).f2<0>(); // expected-error{{expected expression}}
17   }
18 };
19
20 struct MrsBadcrumble {
21   friend MrsBadcrumble operator<(void (*)(int), MrsBadcrumble);
22   friend void operator>(MrsBadcrumble, int);
23 } mb;
24
25 template<int N, typename T> void f(T t) {
26   t.f<N>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'f'}}
27   t.T::f<N>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'f'}}
28   T::g<N>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'g'}}
29
30   // Note: no diagnostic here, this is actually valid as a comparison between
31   // the decayed pointer to Y::g<> and mb!
32   T::g<mb>(0);
33 }
34
35 struct Y {
36   template <int> void f(int);
37   template <int = 0> static void g(int); // expected-warning 0-1{{extension}}
38 };
39 void q() { void (*p)(int) = Y::g; }
40 template void f<0>(Y); // expected-note {{in instantiation of}}
41
42 namespace PR9401 {
43   // From GCC PR c++/45558
44   template <typename S, typename T>
45   struct C
46   {
47     template <typename U>
48     struct B
49     {
50       template <typename W>
51       struct E
52       {
53         explicit E(const W &x) : w(x) {}
54         const W &w;
55       };
56     };
57   };
58
59   struct F;
60   template <typename X>
61   struct D
62   {
63     D() {}
64   };
65
66   const D<F> g;
67   template <typename S, typename T>
68   struct A
69   {
70     template <typename U>
71     struct B : C<S, T>::template B<U>
72     {
73       typedef typename C<S, T>::template B<U> V;
74       static const D<typename V::template E<D<F> > > a;
75     };
76   };
77
78   template <typename S, typename T>
79   template <typename U>
80   const D<typename C<S, T>::template B<U>::template E<D<F> > >
81   A<S, T>::B<U>::a = typename C<S, T>::template B<U>::template E<D<F> >(g);
82 }