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