blob: bcf05fcefc27a3595266085bc922d69986a4cefe [file] [log] [blame]
Douglas Gregorb3bec712008-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'}}
6export template x; // expected-error {{expected '<' after 'template'}}
7template < ; // expected-error {{parse error}}
8template <template X> ; // expected-error {{expected '<' after 'template'}}
9template <template <typename> > ; // expected-error {{expected 'class' before '>'}}
10template <template <typename> Foo> ; // expected-error {{expected 'class' before 'Foo'}}
11
12// Template function declarations
13template <typename T> void foo();
14template <typename T, typename U> void foo();
15
Douglas Gregor8e7f9572008-12-02 00:41:28 +000016// Template function definitions.
17template <typename T> void foo() { }
Douglas Gregorb3bec712008-12-01 23:54:00 +000018
19// Template class (forward) declarations
20template <typename T> struct A;
21template <typename T, typename U> struct b;
22template <typename> struct C;
23template <typename, typename> struct D;
24
25// Forward declarations with default parameters?
26template <typename T = int> X1;
27template <typename = int> X2;
28
29// Forward declarations w/template template parameters
30template <template <typename> class T> class TTP1;
31template <template <typename> class> class TTP2;
32template <template <typename> class T = foo> TTP3;
33template <template <typename> class = foo> TTP3;
34template <template <typename X, typename Y> class T> TTP5;
35
36// Forward declararations with non-type params
37template <int> class NTP0;
38template <int N> class NTP1;
39template <int N = 5> class NTP2;
40template <int = 10> class NTP3;
41template <unsigned int N = 12u> NTP4;;
42template <unsigned int = 12u> NTP5;
43template <unsigned = 15u> NTP6;
Douglas Gregordd861062008-12-05 18:15:24 +000044template <typename T, T Obj> NTP7;
Douglas Gregorb3bec712008-12-01 23:54:00 +000045
46// Template class declarations
47template <typename T> struct A { };
48template <typename T, typename U> struct B { };
49
Douglas Gregordd861062008-12-05 18:15:24 +000050// Template parameter shadowing
51template<typename T, // expected-note{{template parameter is declared here}}
52 typename T> // expected-error{{declaration of 'T' shadows template parameter}}
53 void shadow1();
54
55template<typename T> // expected-note{{template parameter is declared here}}
56void shadow2(int T); // expected-error{{declaration of 'T' shadows template parameter}}
57
58template<typename T> // expected-note{{template parameter is declared here}}
59class T { // expected-error{{declaration of 'T' shadows template parameter}}
60};
61
62template<int Size> // expected-note{{template parameter is declared here}}
63void shadow3(int Size); // expected-error{{declaration of 'Size' shadows template parameter}}
64
65// Non-type template parameters in scope
66template<int Size>
67void f(int& i) {
68 i = Size;
69 Size = i; // expected-error{{expression is not assignable}}
70}
71
72template<typename T>
73const T& min(const T&, const T&);