blob: 94b7069afbe4b56a35958fe6f8e4dafa7482fddb [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify %s
Douglas Gregoradcac882008-12-01 23:54:00 +00002
3// Errors
4export class foo { }; // expected-error {{expected template}}
Douglas Gregor1426e532009-05-12 21:31:51 +00005template x; // expected-error {{C++ requires a type specifier for all declarations}}
Douglas Gregor7cdbc582009-07-22 23:48:44 +00006export template x; // expected-error {{expected '<' after 'template'}}
7export template<class T> class x0; // expected-note {{exported templates are unsupported}}
Sebastian Redla4ed0d82008-12-28 15:28:59 +00008template < ; // expected-error {{parse error}} expected-error {{declaration does not declare anything}}
9template <template X> struct Err1; // expected-error {{expected '<' after 'template'}}
10template <template <typename> > struct Err2; // expected-error {{expected 'class' before '>'}}
11template <template <typename> Foo> struct Err3; // expected-error {{expected 'class' before 'Foo'}}
Douglas Gregoradcac882008-12-01 23:54:00 +000012
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?
Douglas Gregor4310f4e2009-02-16 22:38:20 +000027template <typename T = int> class X1;
28template <typename = int> class X2;
Douglas Gregoradcac882008-12-01 23:54:00 +000029
30// Forward declarations w/template template parameters
31template <template <typename> class T> class TTP1;
32template <template <typename> class> class TTP2;
Douglas Gregore53060f2009-06-25 22:08:12 +000033template <template <typename> class T = foo> class TTP3; // expected-error{{must be a class template}}
34template <template <typename> class = foo> class TTP3; // expected-error{{must be a class template}}
Douglas Gregoraaba5e32009-02-04 19:02:06 +000035template <template <typename X, typename Y> class T> class TTP5;
Douglas Gregoradcac882008-12-01 23:54:00 +000036
Douglas Gregor52591bf2009-06-24 00:54:41 +000037// Forward declarations with non-type params
Douglas Gregoradcac882008-12-01 23:54:00 +000038template <int> class NTP0;
39template <int N> class NTP1;
40template <int N = 5> class NTP2;
41template <int = 10> class NTP3;
Douglas Gregor4310f4e2009-02-16 22:38:20 +000042template <unsigned int N = 12u> class NTP4;
43template <unsigned int = 12u> class NTP5;
44template <unsigned = 15u> class NTP6;
45template <typename T, T Obj> class 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}}
Mike Stump1eb44332009-09-09 15:08:12 +000053 typename T> // expected-error{{declaration of 'T' shadows template parameter}}
Douglas Gregor72c3f312008-12-05 18:15:24 +000054 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
Douglas Gregorc19ee3e2009-06-17 23:37:01 +000066// <rdar://problem/6952203>
67template<typename T> // expected-note{{here}}
68struct shadow4 {
69 int T; // expected-error{{shadows}}
70};
71
72template<typename T> // expected-note{{here}}
73struct shadow5 {
74 int T(int, float); // expected-error{{shadows}}
75};
76
Douglas Gregor72c3f312008-12-05 18:15:24 +000077// Non-type template parameters in scope
78template<int Size>
79void f(int& i) {
80 i = Size;
81 Size = i; // expected-error{{expression is not assignable}}
82}
83
84template<typename T>
85const T& min(const T&, const T&);
Argyrios Kyrtzidis64096252009-05-22 10:22:18 +000086
87void f2() {
88 int x;
89 A< typeof(x>1) > a;
90}