Eli Friedman | 64a4eb2 | 2009-12-27 22:31:18 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fsyntax-only -verify %s -fdelayed-template-parsing |
Eli Friedman | 64a4eb2 | 2009-12-27 22:31:18 +0000 | [diff] [blame] | 3 | |
| 4 | template<typename T> struct A {}; |
| 5 | |
| 6 | // Check for template argument lists followed by junk |
| 7 | // FIXME: The diagnostics here aren't great... |
| 8 | A<int+> int x; // expected-error {{expected '>'}} expected-error {{expected unqualified-id}} |
Richard Smith | a38253c | 2013-07-11 05:10:21 +0000 | [diff] [blame] | 9 | A<int x; // expected-error {{type-id cannot have a name}} expected-error {{expected '>'}} |
Eli Friedman | 64a4eb2 | 2009-12-27 22:31:18 +0000 | [diff] [blame] | 10 | |
Douglas Gregor | bc61bd8 | 2011-01-11 00:33:19 +0000 | [diff] [blame] | 11 | // PR8912 |
| 12 | template <bool> struct S {}; |
| 13 | S<bool(2 > 1)> s; |
Richard Smith | 19a2702 | 2012-06-18 06:11:04 +0000 | [diff] [blame] | 14 | |
| 15 | // Test behavior when a template-id is ended by a token which starts with '>'. |
| 16 | namespace greatergreater { |
| 17 | template<typename T> struct S { S(); S(T); }; |
| 18 | void f(S<int>=0); // expected-error {{a space is required between a right angle bracket and an equals sign (use '> =')}} |
| 19 | void f(S<S<int>>=S<int>()); // expected-error {{use '> >'}} expected-error {{use '> ='}} |
| 20 | template<typename T> void t(); |
| 21 | void g() { |
| 22 | void (*p)() = &t<int>; |
| 23 | (void)(&t<int>==p); // expected-error {{use '> ='}} |
| 24 | (void)(&t<int>>=p); // expected-error {{use '> >'}} |
| 25 | (void)(&t<S<int>>>=p); // expected-error {{use '> >'}} |
| 26 | (void)(&t<S<int>>==p); // expected-error {{use '> >'}} expected-error {{use '> ='}} |
| 27 | } |
| 28 | } |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 29 | |
| 30 | namespace PR5925 { |
| 31 | template <typename x> |
| 32 | class foo { // expected-note {{here}} |
| 33 | }; |
| 34 | void bar(foo *X) { // expected-error {{requires template arguments}} |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | namespace PR13210 { |
| 39 | template <class T> |
| 40 | class C {}; // expected-note {{here}} |
| 41 | |
| 42 | void f() { |
| 43 | new C(); // expected-error {{requires template arguments}} |
| 44 | } |
| 45 | } |
Serge Pavlov | 62f675c | 2013-08-10 05:54:47 +0000 | [diff] [blame] | 46 | |
| 47 | // Don't emit spurious messages |
| 48 | namespace pr16225add { |
| 49 | |
| 50 | template<class T1, typename T2> struct Known { }; // expected-note 3 {{template is declared here}} |
| 51 | template<class T1, typename T2> struct X; |
| 52 | template<class T1, typename T2> struct ABC; // expected-note {{template is declared here}} |
| 53 | template<int N1, int N2> struct ABC2 {}; |
| 54 | |
| 55 | template<class T1, typename T2> struct foo : |
| 56 | UnknownBase<T1,T2> // expected-error {{unknown template name 'UnknownBase'}} |
| 57 | { }; |
| 58 | |
| 59 | template<class T1, typename T2> struct foo2 : |
| 60 | UnknownBase<T1,T2>, // expected-error {{unknown template name 'UnknownBase'}} |
| 61 | Known<T1> // expected-error {{too few template arguments for class template 'Known'}} |
| 62 | { }; |
| 63 | |
| 64 | template<class T1, typename T2> struct foo3 : |
| 65 | UnknownBase<T1,T2,ABC<T2,T1> > // expected-error {{unknown template name 'UnknownBase'}} |
| 66 | { }; |
| 67 | |
| 68 | template<class T1, typename T2> struct foo4 : |
| 69 | UnknownBase<T1,ABC<T2> >, // expected-error {{unknown template name 'UnknownBase'}} \ |
| 70 | // expected-error {{too few template arguments for class template 'ABC'}} |
| 71 | Known<T1> // expected-error {{too few template arguments for class template 'Known'}} |
| 72 | { }; |
| 73 | |
| 74 | template<class T1, typename T2> struct foo5 : |
| 75 | UnknownBase<T1,T2,ABC<T2,T1>> // expected-error {{unknown template name 'UnknownBase'}} \ |
| 76 | // expected-error {{use '> >'}} |
| 77 | { }; |
| 78 | |
| 79 | template<class T1, typename T2> struct foo6 : |
| 80 | UnknownBase<T1,ABC<T2,T1>>, // expected-error {{unknown template name 'UnknownBase'}} \ |
| 81 | // expected-error {{use '> >'}} |
| 82 | Known<T1> // expected-error {{too few template arguments for class template 'Known'}} |
| 83 | { }; |
| 84 | |
| 85 | template<class T1, typename T2, int N> struct foo7 : |
| 86 | UnknownBase<T1,T2,(N>1)> // expected-error {{unknown template name 'UnknownBase'}} |
| 87 | { }; |
| 88 | |
| 89 | template<class T1, typename T2> struct foo8 : |
| 90 | UnknownBase<X<int,int>,X<int,int>> // expected-error {{unknown template name 'UnknownBase'}} \ |
| 91 | // expected-error {{use '> >'}} |
| 92 | { }; |
| 93 | |
| 94 | template<class T1, typename T2> struct foo9 : |
| 95 | UnknownBase<Known<int,int>,X<int,int>> // expected-error {{unknown template name 'UnknownBase'}} \ |
| 96 | // expected-error {{use '> >'}} |
| 97 | { }; |
| 98 | |
| 99 | template<class T1, typename T2> struct foo10 : |
| 100 | UnknownBase<Known<int,int>,X<int,X<int,int>>> // expected-error {{unknown template name 'UnknownBase'}} \ |
| 101 | // expected-error {{use '> >'}} |
| 102 | { }; |
| 103 | |
| 104 | template<int N1, int N2> struct foo11 : |
| 105 | UnknownBase<2<N1,N2<4> // expected-error {{unknown template name 'UnknownBase'}} |
| 106 | { }; |
| 107 | |
| 108 | } |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 109 | |
| 110 | namespace PR18793 { |
| 111 | template<typename T, T> struct S {}; |
| 112 | template<typename T> int g(S<T, (T())> *); |
| 113 | } |