1 // RUN: %clang_cc1 -fsyntax-only -verify %s 2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s 3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 4 // RUN: %clang_cc1 -fsyntax-only -verify %s -fdelayed-template-parsing 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 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-note {{to match this '<'}} expected-error {{expected unqualified-id}} 13 A<int x; // expected-error {{expected '>'}} expected-note {{to match this '<'}} 14 15 // PR8912 16 template <bool> struct S {}; 17 S<bool(2 > 1)> s; 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(); g()25 void g() { 26 void (*p)() = &t<int>; 27 (void)(&t<int>==p); // expected-error {{use '> ='}} 28 (void)(&t<int>>=p); // expected-error {{use '> >'}} 29 (void)(&t<S<int>>>=p); 30 #if __cplusplus <= 199711L 31 // expected-error@-2 {{use '> >'}} 32 #endif 33 (void)(&t<S<int>>==p); // expected-error {{use '> >'}} expected-error {{use '> ='}} 34 } 35 } 36 37 namespace PR5925 { 38 template <typename x> 39 class foo { // expected-note {{here}} 40 }; bar(foo * X)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 f()49 void f() { 50 new C(); // expected-error {{requires template arguments}} 51 } 52 } 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 {{no template named 'UnknownBase'}} 64 { }; 65 66 template<class T1, typename T2> struct foo2 : 67 UnknownBase<T1,T2>, // expected-error {{no template named '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 {{no template named 'UnknownBase'}} 73 { }; 74 75 template<class T1, typename T2> struct foo4 : 76 UnknownBase<T1,ABC<T2> >, // expected-error {{too few template arguments for class template 'ABC'}} 77 Known<T1> // expected-error {{too few template arguments for class template 'Known'}} 78 { }; 79 80 template<class T1, typename T2> struct foo5 : 81 UnknownBase<T1,T2,ABC<T2,T1>> // expected-error {{no template named 'UnknownBase'}} 82 #if __cplusplus <= 199711L 83 // expected-error@-2 {{use '> >'}} 84 #endif 85 { }; 86 87 template<class T1, typename T2> struct foo6 : 88 UnknownBase<T1,ABC<T2,T1>>, // expected-error {{no template named 'UnknownBase'}} 89 #if __cplusplus <= 199711L 90 // expected-error@-2 {{use '> >'}} 91 #endif 92 Known<T1> // expected-error {{too few template arguments for class template 'Known'}} 93 { }; 94 95 template<class T1, typename T2, int N> struct foo7 : 96 UnknownBase<T1,T2,(N>1)> // expected-error {{no template named 'UnknownBase'}} 97 { }; 98 99 template<class T1, typename T2> struct foo8 : 100 UnknownBase<X<int,int>,X<int,int>> // expected-error {{no template named 'UnknownBase'}} 101 #if __cplusplus <= 199711L 102 // expected-error@-2 {{use '> >'}} 103 #endif 104 { }; 105 106 template<class T1, typename T2> struct foo9 : 107 UnknownBase<Known<int,int>,X<int,int>> // expected-error {{no template named 'UnknownBase'}} 108 #if __cplusplus <= 199711L 109 // expected-error@-2 {{use '> >'}} 110 #endif 111 { }; 112 113 template<class T1, typename T2> struct foo10 : 114 UnknownBase<Known<int,int>,X<int,X<int,int>>> // expected-error {{no template named 'UnknownBase'}} 115 #if __cplusplus <= 199711L 116 // expected-error@-2 {{use '> >'}} 117 #endif 118 { }; 119 120 template<int N1, int N2> struct foo11 : 121 UnknownBase<2<N1,N2<4> // expected-error {{no template named 'UnknownBase'}} 122 { }; 123 124 } 125 126 namespace PR18793 { 127 template<typename T, T> struct S {}; 128 template<typename T> int g(S<T, (T())> *); 129 } 130 131 namespace r360308_regression { 132 template<typename> struct S1 { static int const n = 0; }; 133 template<int, typename> struct S2 { typedef int t; }; 134 template<typename T> struct S3 { typename S2<S1<T>::n < 0, int>::t n; }; 135 f(FT p)136 template<typename FT> bool f(FT p) { 137 const bool a = p.first<FT(0), b = p.second>FT(0); 138 return a == b; 139 } 140 } 141