1 // RUN: clang-cc -fsyntax-only -verify %s 2 3 // Errors 4 export class foo { }; // expected-error {{expected template}} 5 template x; // expected-error {{C++ requires a type specifier for all declarations}} 6 export template x; // expected-error {{expected '<' after 'template'}} 7 export template<class T> class x0; // expected-note {{exported templates are unsupported}} 8 template < ; // expected-error {{parse error}} expected-error {{declaration does not declare anything}} 9 template <template X> struct Err1; // expected-error {{expected '<' after 'template'}} 10 template <template <typename> > struct Err2; // expected-error {{expected 'class' before '>'}} 11 template <template <typename> Foo> struct Err3; // expected-error {{expected 'class' before 'Foo'}} 12 13 // Template function declarations 14 template <typename T> void foo(); 15 template <typename T, typename U> void foo(); 16 17 // Template function definitions. 18 template <typename T> void foo() { } 19 20 // Template class (forward) declarations 21 template <typename T> struct A; 22 template <typename T, typename U> struct b; 23 template <typename> struct C; 24 template <typename, typename> struct D; 25 26 // Forward declarations with default parameters? 27 template <typename T = int> class X1; 28 template <typename = int> class X2; 29 30 // Forward declarations w/template template parameters 31 template <template <typename> class T> class TTP1; 32 template <template <typename> class> class TTP2; 33 template <template <typename> class T = foo> class TTP3; // expected-error{{must be a class template}} 34 template <template <typename> class = foo> class TTP3; // expected-error{{must be a class template}} 35 template <template <typename X, typename Y> class T> class TTP5; 36 37 // Forward declarations with non-type params 38 template <int> class NTP0; 39 template <int N> class NTP1; 40 template <int N = 5> class NTP2; 41 template <int = 10> class NTP3; 42 template <unsigned int N = 12u> class NTP4; 43 template <unsigned int = 12u> class NTP5; 44 template <unsigned = 15u> class NTP6; 45 template <typename T, T Obj> class NTP7; 46 47 // Template class declarations 48 template <typename T> struct A { }; 49 template <typename T, typename U> struct B { }; 50 51 // Template parameter shadowing 52 template<typename T, // expected-note{{template parameter is declared here}} 53 typename T> // expected-error{{declaration of 'T' shadows template parameter}} 54 void shadow1(); 55 56 template<typename T> // expected-note{{template parameter is declared here}} 57 void shadow2(int T); // expected-error{{declaration of 'T' shadows template parameter}} 58 59 template<typename T> // expected-note{{template parameter is declared here}} 60 class T { // expected-error{{declaration of 'T' shadows template parameter}} 61 }; 62 63 template<int Size> // expected-note{{template parameter is declared here}} 64 void shadow3(int Size); // expected-error{{declaration of 'Size' shadows template parameter}} 65 66 // <rdar://problem/6952203> 67 template<typename T> // expected-note{{here}} 68 struct shadow4 { 69 int T; // expected-error{{shadows}} 70 }; 71 72 template<typename T> // expected-note{{here}} 73 struct shadow5 { 74 int T(int, float); // expected-error{{shadows}} 75 }; 76 77 // Non-type template parameters in scope 78 template<int Size> 79 void f(int& i) { 80 i = Size; 81 Size = i; // expected-error{{expression is not assignable}} 82 } 83 84 template<typename T> 85 const T& min(const T&, const T&); 86 87 void f2() { 88 int x; 89 A< typeof(x>1) > a; 90 } 91