blob: 4717dbb7dc2d396c4d2790a984b300def2550ea7 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregoradcac882008-12-01 23:54:00 +00002
3// Errors
4export class foo { }; // expected-error {{expected template}}
Douglas Gregord5a423b2009-09-25 18:43:00 +00005template x; // expected-error {{C++ requires a type specifier for all declarations}} \
6 // expected-error {{does not refer}}
Douglas Gregor7cdbc582009-07-22 23:48:44 +00007export template x; // expected-error {{expected '<' after 'template'}}
Douglas Gregor51ffb0c2009-11-25 18:55:14 +00008export template<class T> class x0; // expected-warning {{exported templates are unsupported}}
Douglas Gregor99ea7342010-10-15 01:15:58 +00009template < ; // expected-error {{parse error}} \
10// expected-error{{expected ',' or '>' in template-parameter-list}} \
11// expected-warning {{declaration does not declare anything}}
Douglas Gregorf6b11852009-10-08 15:14:33 +000012template <template X> struct Err1; // expected-error {{expected '<' after 'template'}} \
13// expected-error{{extraneous}}
14template <template <typename> > struct Err2; // expected-error {{expected 'class' before '>'}} \
15// expected-error{{extraneous}}
16template <template <typename> Foo> struct Err3; // expected-error {{expected 'class' before 'Foo'}} \
17// expected-error{{extraneous}}
Douglas Gregoradcac882008-12-01 23:54:00 +000018
19// Template function declarations
20template <typename T> void foo();
21template <typename T, typename U> void foo();
22
Douglas Gregor26236e82008-12-02 00:41:28 +000023// Template function definitions.
24template <typename T> void foo() { }
Douglas Gregoradcac882008-12-01 23:54:00 +000025
26// Template class (forward) declarations
27template <typename T> struct A;
28template <typename T, typename U> struct b;
29template <typename> struct C;
30template <typename, typename> struct D;
31
32// Forward declarations with default parameters?
Douglas Gregor4310f4e2009-02-16 22:38:20 +000033template <typename T = int> class X1;
34template <typename = int> class X2;
Douglas Gregoradcac882008-12-01 23:54:00 +000035
36// Forward declarations w/template template parameters
37template <template <typename> class T> class TTP1;
38template <template <typename> class> class TTP2;
Douglas Gregore53060f2009-06-25 22:08:12 +000039template <template <typename> class T = foo> class TTP3; // expected-error{{must be a class template}}
40template <template <typename> class = foo> class TTP3; // expected-error{{must be a class template}}
Douglas Gregoraaba5e32009-02-04 19:02:06 +000041template <template <typename X, typename Y> class T> class TTP5;
Douglas Gregoradcac882008-12-01 23:54:00 +000042
Douglas Gregor52591bf2009-06-24 00:54:41 +000043// Forward declarations with non-type params
Douglas Gregoradcac882008-12-01 23:54:00 +000044template <int> class NTP0;
45template <int N> class NTP1;
46template <int N = 5> class NTP2;
47template <int = 10> class NTP3;
Douglas Gregor4310f4e2009-02-16 22:38:20 +000048template <unsigned int N = 12u> class NTP4;
49template <unsigned int = 12u> class NTP5;
50template <unsigned = 15u> class NTP6;
51template <typename T, T Obj> class NTP7;
Douglas Gregoradcac882008-12-01 23:54:00 +000052
53// Template class declarations
54template <typename T> struct A { };
55template <typename T, typename U> struct B { };
56
Douglas Gregor72c3f312008-12-05 18:15:24 +000057// Template parameter shadowing
58template<typename T, // expected-note{{template parameter is declared here}}
Mike Stump1eb44332009-09-09 15:08:12 +000059 typename T> // expected-error{{declaration of 'T' shadows template parameter}}
Douglas Gregor72c3f312008-12-05 18:15:24 +000060 void shadow1();
61
62template<typename T> // expected-note{{template parameter is declared here}}
63void shadow2(int T); // expected-error{{declaration of 'T' shadows template parameter}}
64
65template<typename T> // expected-note{{template parameter is declared here}}
66class T { // expected-error{{declaration of 'T' shadows template parameter}}
67};
68
69template<int Size> // expected-note{{template parameter is declared here}}
70void shadow3(int Size); // expected-error{{declaration of 'Size' shadows template parameter}}
71
Douglas Gregorc19ee3e2009-06-17 23:37:01 +000072// <rdar://problem/6952203>
73template<typename T> // expected-note{{here}}
74struct shadow4 {
75 int T; // expected-error{{shadows}}
76};
77
78template<typename T> // expected-note{{here}}
79struct shadow5 {
80 int T(int, float); // expected-error{{shadows}}
81};
82
Douglas Gregor72c3f312008-12-05 18:15:24 +000083// Non-type template parameters in scope
84template<int Size>
85void f(int& i) {
86 i = Size;
87 Size = i; // expected-error{{expression is not assignable}}
88}
89
90template<typename T>
91const T& min(const T&, const T&);
Argyrios Kyrtzidis64096252009-05-22 10:22:18 +000092
93void f2() {
94 int x;
95 A< typeof(x>1) > a;
96}
Douglas Gregor2cc782f2009-10-30 21:46:58 +000097
98
99// PR3844
100template <> struct S<int> { }; // expected-error{{explicit specialization of non-template struct 'S'}}
Douglas Gregor1df0ee92010-02-05 07:07:10 +0000101
102namespace PR6184 {
103 namespace N {
104 template <typename T>
105 void bar(typename T::x);
106 }
107
108 template <typename T>
109 void N::bar(typename T::x) { }
110}