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