Richard Smith | 9a00bbf | 2013-10-16 21:12:00 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify %s -fcxx-exceptions -std=c++1y |
| 2 | |
Richard Smith | 2b2a176 | 2015-12-03 23:24:04 +0000 | [diff] [blame] | 3 | namespace N {} |
| 4 | |
Richard Smith | 9a00bbf | 2013-10-16 21:12:00 +0000 | [diff] [blame] | 5 | template<typename T, // expected-note {{declared here}} |
| 6 | typename T> struct X {}; // expected-error {{declaration of 'T' shadows template parameter}} |
| 7 | |
Serge Pavlov | e50bf75 | 2016-06-10 04:39:07 +0000 | [diff] [blame] | 8 | template<typename T> struct Y { // expected-note 18{{declared here}} |
Richard Smith | 9a00bbf | 2013-10-16 21:12:00 +0000 | [diff] [blame] | 9 | template<typename T> struct A {}; // expected-error {{declaration of 'T' shadows template parameter}} |
| 10 | |
| 11 | struct B { |
Serge Pavlov | e50bf75 | 2016-06-10 04:39:07 +0000 | [diff] [blame] | 12 | template<typename> struct T {}; // expected-error {{declaration of 'T' shadows template parameter}} |
Richard Smith | 9a00bbf | 2013-10-16 21:12:00 +0000 | [diff] [blame] | 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 | } |
Richard Smith | 2b2a176 | 2015-12-03 23:24:04 +0000 | [diff] [blame] | 55 | void e() { |
| 56 | namespace T = N; // expected-error {{declaration of 'T' shadows template parameter}} |
| 57 | } |
Richard Smith | 9a00bbf | 2013-10-16 21:12:00 +0000 | [diff] [blame] | 58 | |
Richard Smith | 9f95182 | 2016-01-06 22:49:11 +0000 | [diff] [blame] | 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 | } |
Richard Smith | 9a00bbf | 2013-10-16 21:12:00 +0000 | [diff] [blame] | 65 | friend struct T; // expected-error {{declaration of 'T' shadows template parameter}} |
| 66 | }; |
| 67 | |
Serge Pavlov | e50bf75 | 2016-06-10 04:39:07 +0000 | [diff] [blame] | 68 | template<int T> struct Z { // expected-note 16{{declared here}} |
Richard Smith | 9f95182 | 2016-01-06 22:49:11 +0000 | [diff] [blame] | 69 | template<typename T> struct A {}; // expected-error {{declaration of 'T' shadows template parameter}} |
| 70 | |
| 71 | struct B { |
Serge Pavlov | e50bf75 | 2016-06-10 04:39:07 +0000 | [diff] [blame] | 72 | template<typename> struct T {}; // expected-error {{declaration of 'T' shadows template parameter}} |
Richard Smith | 9f95182 | 2016-01-06 22:49:11 +0000 | [diff] [blame] | 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 | |
Richard Smith | 9a00bbf | 2013-10-16 21:12:00 +0000 | [diff] [blame] | 127 | template<typename T> // expected-note {{declared here}} |
| 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 { |
Serge Pavlov | e50bf75 | 2016-06-10 04:39:07 +0000 | [diff] [blame] | 132 | template<typename T> struct T {}; // expected-error{{declaration of 'T' shadows template parameter}} |
| 133 | // expected-note@-1{{template parameter is declared here}} |
Richard Smith | 9a00bbf | 2013-10-16 21:12:00 +0000 | [diff] [blame] | 134 | } |
| 135 | namespace B { |
| 136 | template<typename T> void T() {} |
| 137 | } |
| 138 | namespace C { |
| 139 | template<typename T> int T; |
| 140 | } |
Serge Pavlov | e50bf75 | 2016-06-10 04:39:07 +0000 | [diff] [blame] | 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 | } |