Douglas Gregor | 786123d | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 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 | |
Richard Smith | bf5bcf2 | 2018-06-26 23:20:26 +0000 | [diff] [blame] | 8 | 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 Gregor | 786123d | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 11 | |
Douglas Gregor | 20c38a7 | 2010-05-21 23:43:39 +0000 | [diff] [blame] | 12 | 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 Smith | bf5bcf2 | 2018-06-26 23:20:26 +0000 | [diff] [blame] | 15 | (*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 Gregor | 786123d | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 35 | } |
Richard Smith | bf5bcf2 | 2018-06-26 23:20:26 +0000 | [diff] [blame] | 36 | |
| 37 | int xyz; |
Douglas Gregor | 786123d | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 38 | }; |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 39 | |
Richard Smith | bf5bcf2 | 2018-06-26 23:20:26 +0000 | [diff] [blame] | 40 | template <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 Smith | 17c5947 | 2017-06-07 00:29:44 +0000 | [diff] [blame] | 61 | struct MrsBadcrumble { |
| 62 | friend MrsBadcrumble operator<(void (*)(int), MrsBadcrumble); |
| 63 | friend void operator>(MrsBadcrumble, int); |
| 64 | } mb; |
| 65 | |
| 66 | template<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 Smith | bf5bcf2 | 2018-06-26 23:20:26 +0000 | [diff] [blame] | 74 | |
| 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 Smith | 17c5947 | 2017-06-07 00:29:44 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | struct Y { |
| 80 | template <int> void f(int); |
| 81 | template <int = 0> static void g(int); // expected-warning 0-1{{extension}} |
| 82 | }; |
| 83 | void q() { void (*p)(int) = Y::g; } |
| 84 | template void f<0>(Y); // expected-note {{in instantiation of}} |
| 85 | |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 86 | namespace 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 | } |