Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
| 2 | |
| 3 | // Errors |
| 4 | export class foo { }; // expected-error {{expected template}} |
| 5 | template x; // expected-error {{expected '<' after 'template'}} |
Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame^] | 6 | export template x; // expected-error {{expected '<' after 'template'}} \ |
| 7 | // expected-note {{exported templates are unsupported}} |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 8 | template < ; // expected-error {{parse error}} |
| 9 | template <template X> ; // expected-error {{expected '<' after 'template'}} |
| 10 | template <template <typename> > ; // expected-error {{expected 'class' before '>'}} |
| 11 | template <template <typename> Foo> ; // 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 | |
Douglas Gregor | 26236e8 | 2008-12-02 00:41:28 +0000 | [diff] [blame] | 17 | // Template function definitions. |
| 18 | template <typename T> void foo() { } |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 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> X1; |
| 28 | template <typename = int> 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> TTP3; |
| 34 | template <template <typename> class = foo> TTP3; |
| 35 | template <template <typename X, typename Y> class T> TTP5; |
| 36 | |
| 37 | // Forward declararations 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> NTP4;; |
| 43 | template <unsigned int = 12u> NTP5; |
| 44 | template <unsigned = 15u> NTP6; |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 45 | template <typename T, T Obj> NTP7; |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 46 | |
| 47 | // Template class declarations |
| 48 | template <typename T> struct A { }; |
| 49 | template <typename T, typename U> struct B { }; |
| 50 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 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 | // Non-type template parameters in scope |
| 67 | template<int Size> |
| 68 | void f(int& i) { |
| 69 | i = Size; |
| 70 | Size = i; // expected-error{{expression is not assignable}} |
| 71 | } |
| 72 | |
| 73 | template<typename T> |
| 74 | const T& min(const T&, const T&); |