blob: 3f8f1ec9d0be9f011808e8c09daf99acf3006c22 [file] [log] [blame]
Shih-wei Liaof8fd82b2010-02-10 11:10:31 -08001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3// Errors
4export class foo { }; // expected-error {{expected template}}
5template x; // expected-error {{C++ requires a type specifier for all declarations}} \
6 // expected-error {{does not refer}}
7export template x; // expected-error {{expected '<' after 'template'}}
8export template<class T> class x0; // expected-warning {{exported templates are unsupported}}
9template < ; // expected-error {{parse error}} expected-error {{declaration does not declare anything}}
10template <template X> struct Err1; // expected-error {{expected '<' after 'template'}} \
11// expected-error{{extraneous}}
12template <template <typename> > struct Err2; // expected-error {{expected 'class' before '>'}} \
13// expected-error{{extraneous}}
14template <template <typename> Foo> struct Err3; // expected-error {{expected 'class' before 'Foo'}} \
15// expected-error{{extraneous}}
16
17// Template function declarations
18template <typename T> void foo();
19template <typename T, typename U> void foo();
20
21// Template function definitions.
22template <typename T> void foo() { }
23
24// Template class (forward) declarations
25template <typename T> struct A;
26template <typename T, typename U> struct b;
27template <typename> struct C;
28template <typename, typename> struct D;
29
30// Forward declarations with default parameters?
31template <typename T = int> class X1;
32template <typename = int> class X2;
33
34// Forward declarations w/template template parameters
35template <template <typename> class T> class TTP1;
36template <template <typename> class> class TTP2;
37template <template <typename> class T = foo> class TTP3; // expected-error{{must be a class template}}
38template <template <typename> class = foo> class TTP3; // expected-error{{must be a class template}}
39template <template <typename X, typename Y> class T> class TTP5;
40
41// Forward declarations with non-type params
42template <int> class NTP0;
43template <int N> class NTP1;
44template <int N = 5> class NTP2;
45template <int = 10> class NTP3;
46template <unsigned int N = 12u> class NTP4;
47template <unsigned int = 12u> class NTP5;
48template <unsigned = 15u> class NTP6;
49template <typename T, T Obj> class NTP7;
50
51// Template class declarations
52template <typename T> struct A { };
53template <typename T, typename U> struct B { };
54
55// Template parameter shadowing
56template<typename T, // expected-note{{template parameter is declared here}}
57 typename T> // expected-error{{declaration of 'T' shadows template parameter}}
58 void shadow1();
59
60template<typename T> // expected-note{{template parameter is declared here}}
61void shadow2(int T); // expected-error{{declaration of 'T' shadows template parameter}}
62
63template<typename T> // expected-note{{template parameter is declared here}}
64class T { // expected-error{{declaration of 'T' shadows template parameter}}
65};
66
67template<int Size> // expected-note{{template parameter is declared here}}
68void shadow3(int Size); // expected-error{{declaration of 'Size' shadows template parameter}}
69
70// <rdar://problem/6952203>
71template<typename T> // expected-note{{here}}
72struct shadow4 {
73 int T; // expected-error{{shadows}}
74};
75
76template<typename T> // expected-note{{here}}
77struct shadow5 {
78 int T(int, float); // expected-error{{shadows}}
79};
80
81// Non-type template parameters in scope
82template<int Size>
83void f(int& i) {
84 i = Size;
85 Size = i; // expected-error{{expression is not assignable}}
86}
87
88template<typename T>
89const T& min(const T&, const T&);
90
91void f2() {
92 int x;
93 A< typeof(x>1) > a;
94}
95
96
97// PR3844
98template <> struct S<int> { }; // expected-error{{explicit specialization of non-template struct 'S'}}
99
100namespace PR6184 {
101 namespace N {
102 template <typename T>
103 void bar(typename T::x);
104 }
105
106 template <typename T>
107 void N::bar(typename T::x) { }
108}