1 // RUN: %clang_cc1 -verify %s -fcxx-exceptions -std=c++1y
2
3 namespace N {}
4
5 template<typename T, // expected-note {{declared here}}
6 typename T> struct X {}; // expected-error {{declaration of 'T' shadows template parameter}}
7
8 template<typename T> struct Y { // expected-note 18{{declared here}}
9 template<typename T> struct A {}; // expected-error {{declaration of 'T' shadows template parameter}}
10
11 struct B {
12 template<typename> struct T {}; // expected-error {{declaration of 'T' shadows template parameter}}
13 };
14 struct C {
15 template<typename> void T(); // expected-error {{declaration of 'T' shadows template parameter}}
16 };
17 struct D {
18 struct T {}; // expected-error {{declaration of 'T' shadows template parameter}}
19 };
20 struct E {
21 typedef int T; // expected-error {{declaration of 'T' shadows template parameter}}
22 };
23 struct F {
24 using T = int; // expected-error {{declaration of 'T' shadows template parameter}}
25 };
26 struct G {
27 int T; // expected-error {{declaration of 'T' shadows template parameter}}
28 };
29 struct H {
30 static int T; // expected-error {{declaration of 'T' shadows template parameter}}
31 };
32 struct I {
33 void T(); // expected-error {{declaration of 'T' shadows template parameter}}
34 };
35 struct J {
36 enum T { e }; // expected-error {{declaration of 'T' shadows template parameter}}
37 };
38 struct K {
39 enum E { T }; // expected-error {{declaration of 'T' shadows template parameter}}
40 };
41
aY42 void a() {
43 extern int T; // expected-error {{declaration of 'T' shadows template parameter}}
44 }
bY45 void b() {
46 int T; // expected-error {{declaration of 'T' shadows template parameter}}
47 }
cY48 void c() {
49 try {}
50 catch (int T) {} // expected-error {{declaration of 'T' shadows template parameter}}
51 }
dY52 void d() {
53 void T(); // expected-error {{declaration of 'T' shadows template parameter}}
54 }
eY55 void e() {
56 namespace T = N; // expected-error {{declaration of 'T' shadows template parameter}}
57 }
58
59 // FIXME: These diagnostics are poorly worded. Lookup for the elaborated type
60 // specifier finds the template parameter in this case, which is ill-formed
61 // because it's not a struct.
fY62 void f() {
63 struct T *p; // expected-error {{declaration of 'T' shadows template parameter}}
64 }
65 friend struct T; // expected-error {{declaration of 'T' shadows template parameter}}
66 };
67
68 template<int T> struct Z { // expected-note 16{{declared here}}
69 template<typename T> struct A {}; // expected-error {{declaration of 'T' shadows template parameter}}
70
71 struct B {
72 template<typename> struct T {}; // expected-error {{declaration of 'T' shadows template parameter}}
73 };
74 struct C {
75 template<typename> void T(); // expected-error {{declaration of 'T' shadows template parameter}}
76 };
77 struct D {
78 struct T {}; // expected-error {{declaration of 'T' shadows template parameter}}
79 };
80 struct E {
81 typedef int T; // expected-error {{declaration of 'T' shadows template parameter}}
82 };
83 struct F {
84 using T = int; // expected-error {{declaration of 'T' shadows template parameter}}
85 };
86 struct G {
87 int T; // expected-error {{declaration of 'T' shadows template parameter}}
88 };
89 struct H {
90 static int T; // expected-error {{declaration of 'T' shadows template parameter}}
91 };
92 struct I {
93 void T(); // expected-error {{declaration of 'T' shadows template parameter}}
94 };
95 struct J {
96 enum T { e }; // expected-error {{declaration of 'T' shadows template parameter}}
97 };
98 struct K {
99 enum E { T }; // expected-error {{declaration of 'T' shadows template parameter}}
100 };
101
aZ102 void a() {
103 extern int T; // expected-error {{declaration of 'T' shadows template parameter}}
104 }
bZ105 void b() {
106 int T; // expected-error {{declaration of 'T' shadows template parameter}}
107 }
cZ108 void c() {
109 try {}
110 catch (int T) {} // expected-error {{declaration of 'T' shadows template parameter}}
111 }
dZ112 void d() {
113 void T(); // expected-error {{declaration of 'T' shadows template parameter}}
114 }
eZ115 void e() {
116 namespace T = N; // expected-error {{declaration of 'T' shadows template parameter}}
117 }
118
119 // These cases are valid when 'T' is a non-type template parameter, as T
120 // names an injected struct ::T, which doesn't shadow the template parameter.
fZ121 void f() {
122 struct T *p;
123 }
124 friend struct T;
125 };
126
127 template<typename T> // expected-note {{declared here}}
f(int T)128 void f(int T) {} // expected-error {{declaration of 'T' shadows template parameter}}
129
130 // FIXME: These are ill-formed: a template-parameter shall not have the same name as the template name.
131 namespace A {
132 template<typename T> struct T {}; // expected-error{{declaration of 'T' shadows template parameter}}
133 // expected-note@-1{{template parameter is declared here}}
134 }
135 namespace B {
T()136 template<typename T> void T() {}
137 }
138 namespace C {
139 template<typename T> int T;
140 }
141
142 namespace PR28023 {
143 template<int V> // expected-note{{template parameter is declared here}}
144 struct A {
145 struct B {
146 template <int> friend struct V; // expected-error{{declaration of 'V' shadows template parameter}}
147 };
148 };
149 A<0>::B a;
150 }
151