blob: 617950a4da23394a9a8f042a759b97397713549c [file] [log] [blame]
Douglas Gregor786123d2010-05-21 23:18:07 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2template<typename T, typename U, int N>
3struct 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
Richard Smithbf5bcf22018-06-26 23:20:26 +00008 t->operator+<U const, 1>(1); // expected-error{{use 'template' keyword to treat 'operator +' as a dependent template name}}
9 t->f1<int const, 2>(1); // expected-error{{use 'template' keyword to treat 'f1' as a dependent template name}}
10 t->f1<3, int const>(1); // expected-error{{missing 'template' keyword prior to dependent template name 'f1'}}
Douglas Gregor786123d2010-05-21 23:18:07 +000011
Douglas Gregor20c38a72010-05-21 23:43:39 +000012 T::getAs<U>(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}}
13 t->T::getAs<U>(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}}
14
Richard Smithbf5bcf22018-06-26 23:20:26 +000015 (*t).f2<N>(); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
16 (*t).f2<0>(); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
17 T::f2<0>(); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
18 T::f2<0, int>(0); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
19
20 T::foo<N < 2 || N >= 4>(); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
21
22 // If there are multiple potential template names, pick the one where there
23 // is no whitespace between the name and the '<'.
24 T::foo<T::bar < 1>(); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
25 T::foo < T::bar<1>(); // expected-error{{missing 'template' keyword prior to dependent template name 'bar'}}
26
27 // Prefer to diagonse a missing 'template' keyword rather than finding a non-template name.
28 xyz < T::foo < 1 > (); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
29 T::foo < xyz < 1 > (); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
30
31 // ... even if the whitespace suggests the other name is the template name.
32 // FIXME: Is this the right heuristic?
33 xyz<T::foo < 1>(); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
34 T::foo < xyz<1>(); // expected-error{{missing 'template' keyword prior to dependent template name 'foo'}}
Douglas Gregor786123d2010-05-21 23:18:07 +000035 }
Richard Smithbf5bcf22018-06-26 23:20:26 +000036
37 int xyz;
Douglas Gregor786123d2010-05-21 23:18:07 +000038};
Douglas Gregor23648d72011-03-04 18:53:13 +000039
Richard Smithbf5bcf22018-06-26 23:20:26 +000040template <typename T> void not_missing_template(T t) {
41 (T::n < 0) > (
42 ) // expected-error {{expected expression}}
43 ;
44
45 int a = T::x < 3;
46 int b = T::y > (); // expected-error {{expected expression}}
47
48 void c(int = T::x < 3);
49 void d(int = T::y > ()); // expected-error {{expected expression}}
50
51 for (int x = t < 3 ? 1 : 2; t > (); ++t) { // expected-error {{expected expression}}
52 }
53
54 // FIXME: We shouldn't treat 'T::t' as a potential template-name here,
55 // because that would leave a '?' with no matching ':'.
56 // We should probably generally treat '?' ... ':' as a bracket-like
57 // construct.
58 bool k = T::t < 3 ? 1 > () : false; // expected-error {{missing 'template' keyword}} expected-error +{{}} expected-note +{{}}
59}
60
Richard Smith17c59472017-06-07 00:29:44 +000061struct MrsBadcrumble {
62 friend MrsBadcrumble operator<(void (*)(int), MrsBadcrumble);
63 friend void operator>(MrsBadcrumble, int);
64} mb;
65
66template<int N, typename T> void f(T t) {
67 t.f<N>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'f'}}
68 t.T::f<N>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'f'}}
69 T::g<N>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'g'}}
70
71 // Note: no diagnostic here, this is actually valid as a comparison between
72 // the decayed pointer to Y::g<> and mb!
73 T::g<mb>(0);
Richard Smithbf5bcf22018-06-26 23:20:26 +000074
75 // ... but this one must be a template-id.
76 T::g<mb, int>(0); // expected-error {{missing 'template' keyword prior to dependent template name 'g'}}
Richard Smith17c59472017-06-07 00:29:44 +000077}
78
79struct Y {
80 template <int> void f(int);
81 template <int = 0> static void g(int); // expected-warning 0-1{{extension}}
82};
83void q() { void (*p)(int) = Y::g; }
84template void f<0>(Y); // expected-note {{in instantiation of}}
85
Douglas Gregor23648d72011-03-04 18:53:13 +000086namespace PR9401 {
87 // From GCC PR c++/45558
88 template <typename S, typename T>
89 struct C
90 {
91 template <typename U>
92 struct B
93 {
94 template <typename W>
95 struct E
96 {
97 explicit E(const W &x) : w(x) {}
98 const W &w;
99 };
100 };
101 };
102
103 struct F;
104 template <typename X>
105 struct D
106 {
107 D() {}
108 };
109
110 const D<F> g;
111 template <typename S, typename T>
112 struct A
113 {
114 template <typename U>
115 struct B : C<S, T>::template B<U>
116 {
117 typedef typename C<S, T>::template B<U> V;
118 static const D<typename V::template E<D<F> > > a;
119 };
120 };
121
122 template <typename S, typename T>
123 template <typename U>
124 const D<typename C<S, T>::template B<U>::template E<D<F> > >
125 A<S, T>::B<U>::a = typename C<S, T>::template B<U>::template E<D<F> >(g);
126}