blob: 53813776e77edeadb8af9434514732abe73872c9 [file] [log] [blame]
Douglas Gregoradcac882008-12-01 23:54:00 +00001// RUN: clang -fsyntax-only -verify %s
2
3// Errors
4export class foo { }; // expected-error {{expected template}}
5template x; // expected-error {{expected '<' after 'template'}}
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00006export template x; // expected-error {{expected '<' after 'template'}} \
7 // expected-note {{exported templates are unsupported}}
Douglas Gregoradcac882008-12-01 23:54:00 +00008template < ; // expected-error {{parse error}}
9template <template X> ; // expected-error {{expected '<' after 'template'}}
10template <template <typename> > ; // expected-error {{expected 'class' before '>'}}
11template <template <typename> Foo> ; // expected-error {{expected 'class' before 'Foo'}}
12
13// Template function declarations
14template <typename T> void foo();
15template <typename T, typename U> void foo();
16
Douglas Gregor26236e82008-12-02 00:41:28 +000017// Template function definitions.
18template <typename T> void foo() { }
Douglas Gregoradcac882008-12-01 23:54:00 +000019
20// Template class (forward) declarations
21template <typename T> struct A;
22template <typename T, typename U> struct b;
23template <typename> struct C;
24template <typename, typename> struct D;
25
26// Forward declarations with default parameters?
27template <typename T = int> X1;
28template <typename = int> X2;
29
30// Forward declarations w/template template parameters
31template <template <typename> class T> class TTP1;
32template <template <typename> class> class TTP2;
33template <template <typename> class T = foo> TTP3;
34template <template <typename> class = foo> TTP3;
35template <template <typename X, typename Y> class T> TTP5;
36
37// Forward declararations with non-type params
38template <int> class NTP0;
39template <int N> class NTP1;
40template <int N = 5> class NTP2;
41template <int = 10> class NTP3;
42template <unsigned int N = 12u> NTP4;;
43template <unsigned int = 12u> NTP5;
44template <unsigned = 15u> NTP6;
Douglas Gregor72c3f312008-12-05 18:15:24 +000045template <typename T, T Obj> NTP7;
Douglas Gregoradcac882008-12-01 23:54:00 +000046
47// Template class declarations
48template <typename T> struct A { };
49template <typename T, typename U> struct B { };
50
Douglas Gregor72c3f312008-12-05 18:15:24 +000051// Template parameter shadowing
52template<typename T, // expected-note{{template parameter is declared here}}
53 typename T> // expected-error{{declaration of 'T' shadows template parameter}}
54 void shadow1();
55
56template<typename T> // expected-note{{template parameter is declared here}}
57void shadow2(int T); // expected-error{{declaration of 'T' shadows template parameter}}
58
59template<typename T> // expected-note{{template parameter is declared here}}
60class T { // expected-error{{declaration of 'T' shadows template parameter}}
61};
62
63template<int Size> // expected-note{{template parameter is declared here}}
64void shadow3(int Size); // expected-error{{declaration of 'Size' shadows template parameter}}
65
66// Non-type template parameters in scope
67template<int Size>
68void f(int& i) {
69 i = Size;
70 Size = i; // expected-error{{expression is not assignable}}
71}
72
73template<typename T>
74const T& min(const T&, const T&);