| 1 |
// RUN: %clang_cc1 -verify %s -fcxx-exceptions -std=c++1y -Wno-error=strict-primary-template-shadow |
| 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 |
|
| 42 |
void a() { |
| 43 |
extern int T; // expected-error {{declaration of 'T' shadows template parameter}} |
| 44 |
} |
| 45 |
void b() { |
| 46 |
int T; // expected-error {{declaration of 'T' shadows template parameter}} |
| 47 |
} |
| 48 |
void c() { |
| 49 |
try {} |
| 50 |
catch (int T) {} // expected-error {{declaration of 'T' shadows template parameter}} |
| 51 |
} |
| 52 |
void d() { |
| 53 |
void T(); // expected-error {{declaration of 'T' shadows template parameter}} |
| 54 |
} |
| 55 |
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. |
| 62 |
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 |
|
| 102 |
void a() { |
| 103 |
extern int T; // expected-error {{declaration of 'T' shadows template parameter}} |
| 104 |
} |
| 105 |
void b() { |
| 106 |
int T; // expected-error {{declaration of 'T' shadows template parameter}} |
| 107 |
} |
| 108 |
void c() { |
| 109 |
try {} |
| 110 |
catch (int T) {} // expected-error {{declaration of 'T' shadows template parameter}} |
| 111 |
} |
| 112 |
void d() { |
| 113 |
void T(); // expected-error {{declaration of 'T' shadows template parameter}} |
| 114 |
} |
| 115 |
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. |
| 121 |
void f() { |
| 122 |
struct T *p; |
| 123 |
} |
| 124 |
friend struct T; |
| 125 |
}; |
| 126 |
|
| 127 |
template<typename T> // expected-note {{declared here}} |
| 128 |
void f(int T) {} // expected-error {{declaration of 'T' shadows template parameter}} |
| 129 |
|
| 130 |
namespace A { |
| 131 |
template<typename T> struct T {}; // expected-error{{declaration of 'T' shadows template parameter}} |
| 132 |
// expected-note@-1{{template parameter is declared here}} |
| 133 |
template<typename T> struct U { |
| 134 |
template<typename V> struct V {}; // expected-error{{declaration of 'V' shadows template parameter}} |
| 135 |
// expected-note@-1{{template parameter is declared here}} |
| 136 |
}; |
| 137 |
} |
| 138 |
namespace B { |
| 139 |
template<typename T> void T() {} // expected-warning{{declaration of 'T' shadows template parameter}} |
| 140 |
// expected-note@-1{{template parameter is declared here}} |
| 141 |
|
| 142 |
template<typename T> struct U { |
| 143 |
template<typename V> void V(); // expected-warning{{declaration of 'V' shadows template parameter}} |
| 144 |
// expected-note@-1{{template parameter is declared here}} |
| 145 |
}; |
| 146 |
} |
| 147 |
namespace C { |
| 148 |
template<typename T> int T; // expected-warning{{declaration of 'T' shadows template parameter}} |
| 149 |
// expected-note@-1{{template parameter is declared here}} |
| 150 |
template<typename T> struct U { |
| 151 |
template<typename V> static int V; // expected-warning{{declaration of 'V' shadows template parameter}} |
| 152 |
// expected-note@-1{{template parameter is declared here}} |
| 153 |
}; |
| 154 |
} |
| 155 |
|
| 156 |
namespace PR28023 { |
| 157 |
template<int V> // expected-note{{template parameter is declared here}} |
| 158 |
struct A { |
| 159 |
struct B { |
| 160 |
template <int> friend struct V; // expected-error{{declaration of 'V' shadows template parameter}} |
| 161 |
}; |
| 162 |
}; |
| 163 |
A<0>::B a; |
| 164 |
} |
| 165 |
|
| 166 |
template <typename T> int shadow() { // expected-note{{template parameter is declared here}} |
| 167 |
using arr = int[1]; |
| 168 |
// expected-warning@+1 {{structured binding declarations are a C++17 extension}} |
| 169 |
auto [ |
| 170 |
T // expected-error {{declaration of 'T' shadows template parameter}} |
| 171 |
] = arr{}; |
| 172 |
return 0; |
| 173 |
} |
| 174 |
|
| 175 |
auto Use = shadow<int>(); |