Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | fd2300e | 2009-10-29 17:56:10 +0000 | [diff] [blame] | 2 | // PR5336 |
| 3 | template<typename FromCl> |
| 4 | struct isa_impl_cl { |
| 5 | template<class ToCl> |
| 6 | static void isa(const FromCl &Val) { } |
| 7 | }; |
| 8 | |
| 9 | template<class X, class Y> |
| 10 | void isa(const Y &Val) { return isa_impl_cl<Y>::template isa<X>(Val); } |
| 11 | |
| 12 | class Value; |
| 13 | void f0(const Value &Val) { isa<Value>(Val); } |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 14 | |
| 15 | // Implicit template-ids. |
| 16 | template<typename T> |
| 17 | struct X0 { |
| 18 | template<typename U> |
| 19 | void f1(); |
| 20 | |
| 21 | template<typename U> |
| 22 | void f2(U) { |
| 23 | f1<U>(); |
| 24 | } |
| 25 | }; |
| 26 | |
| 27 | void test_X0_int(X0<int> xi, float f) { |
| 28 | xi.f2(f); |
| 29 | } |
Douglas Gregor | ae4c77d | 2010-02-05 19:11:37 +0000 | [diff] [blame] | 30 | |
| 31 | // Not template-id expressions, but they almost look like it. |
| 32 | template<typename F> |
| 33 | struct Y { |
| 34 | Y(const F&); |
| 35 | }; |
| 36 | |
| 37 | template<int I> |
| 38 | struct X { |
| 39 | X(int, int); |
| 40 | void f() { |
| 41 | Y<X<I> >(X<I>(0, 0)); |
| 42 | Y<X<I> >(::X<I>(0, 0)); |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | template struct X<3>; |
Douglas Gregor | 0278e12 | 2010-05-05 05:58:24 +0000 | [diff] [blame] | 47 | |
| 48 | // 'template' as a disambiguator. |
| 49 | // PR7030 |
| 50 | struct Y0 { |
| 51 | template<typename U> |
| 52 | void f1(U); |
| 53 | |
| 54 | template<typename U> |
| 55 | static void f2(U); |
| 56 | |
| 57 | void f3(int); |
| 58 | |
| 59 | static int f4(int); |
| 60 | template<typename U> |
| 61 | static void f4(U); |
| 62 | |
| 63 | template<typename U> |
| 64 | void f() { |
Douglas Gregor | 732281d | 2010-06-14 22:07:54 +0000 | [diff] [blame] | 65 | Y0::template f1<U>(0); // expected-warning{{'template' refers to a non-dependent template name}} |
| 66 | Y0::template f1(0); // expected-warning{{'template' refers to a non-dependent template name}} |
Douglas Gregor | 0278e12 | 2010-05-05 05:58:24 +0000 | [diff] [blame] | 67 | this->template f1(0); |
| 68 | |
Douglas Gregor | 732281d | 2010-06-14 22:07:54 +0000 | [diff] [blame] | 69 | Y0::template f2<U>(0); // expected-warning{{'template' refers to a non-dependent template name}} |
| 70 | Y0::template f2(0);// expected-warning{{'template' refers to a non-dependent template name}} |
Douglas Gregor | 0278e12 | 2010-05-05 05:58:24 +0000 | [diff] [blame] | 71 | |
| 72 | Y0::template f3(0); // expected-error {{'f3' following the 'template' keyword does not refer to a template}} |
| 73 | Y0::template f3(); // expected-error {{'f3' following the 'template' keyword does not refer to a template}} |
| 74 | |
| 75 | int x; |
| 76 | x = Y0::f4(0); |
| 77 | x = Y0::f4<int>(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} |
Douglas Gregor | 732281d | 2010-06-14 22:07:54 +0000 | [diff] [blame] | 78 | x = Y0::template f4(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} \ |
| 79 | // expected-warning{{'template' refers to a non-dependent template name}} |
Douglas Gregor | 0278e12 | 2010-05-05 05:58:24 +0000 | [diff] [blame] | 80 | |
| 81 | x = this->f4(0); |
| 82 | x = this->f4<int>(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} |
| 83 | x = this->template f4(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} |
| 84 | } |
| 85 | }; |