| 1 |
// PR c++/52953 |
| 2 |
// { dg-do compile } |
| 3 |
// { dg-options "-pedantic-errors -Wno-switch-unreachable" } |
| 4 |
|
| 5 |
void |
| 6 |
foo (int x) // { dg-message "'int x' previously declared here" } |
| 7 |
{ |
| 8 |
int x; // { dg-error "declaration of 'int x' shadows a parameter" } |
| 9 |
} |
| 10 |
|
| 11 |
void |
| 12 |
bar (int x) // { dg-message "'int x' previously declared here" } |
| 13 |
try |
| 14 |
{ |
| 15 |
int x; // { dg-error "declaration of 'int x' shadows a parameter" } |
| 16 |
} |
| 17 |
catch (...) |
| 18 |
{ |
| 19 |
} |
| 20 |
|
| 21 |
volatile int v; |
| 22 |
|
| 23 |
void |
| 24 |
baz () |
| 25 |
{ |
| 26 |
#if __cplusplus >= 201103L |
| 27 |
auto f = [] (int x) { int x; }; // { dg-error "declaration of 'int x' shadows a parameter" "" { target c++11 } } |
| 28 |
// { dg-message "'int x' previously declared here" "" { target c++11 } .-1 } |
| 29 |
#endif |
| 30 |
if (int x = 1) // { dg-message "'int x' previously declared here" } |
| 31 |
{ |
| 32 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 33 |
} |
| 34 |
if (int x = 0) // { dg-message "'int x' previously declared here" } |
| 35 |
; |
| 36 |
else |
| 37 |
{ |
| 38 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 39 |
} |
| 40 |
if (int x = 1) // { dg-message "'int x' previously declared here" } |
| 41 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 42 |
if (int x = 0) // { dg-message "'int x' previously declared here" } |
| 43 |
; |
| 44 |
else |
| 45 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 46 |
switch (int x = 1) // { dg-message "'int x' previously declared here" } |
| 47 |
{ |
| 48 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 49 |
default:; |
| 50 |
} |
| 51 |
switch (int x = 1) // { dg-message "'int x' previously declared here" } |
| 52 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 53 |
while (int x = v) // { dg-message "'int x' previously declared here" } |
| 54 |
{ |
| 55 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 56 |
} |
| 57 |
while (int x = v) // { dg-message "'int x' previously declared here" } |
| 58 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 59 |
for (int x = v; x; ++x) // { dg-message "'int x' previously declared here" } |
| 60 |
{ |
| 61 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 62 |
} |
| 63 |
for (int x = v; x; ++x) // { dg-message "'int x' previously declared here" } |
| 64 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 65 |
for (; int x = v; ) // { dg-message "'int x' previously declared here" } |
| 66 |
{ |
| 67 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 68 |
} |
| 69 |
for (; int x = v; ) // { dg-message "'int x' previously declared here" } |
| 70 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 71 |
try |
| 72 |
{ |
| 73 |
} |
| 74 |
catch (int x) // { dg-message "'int x' previously declared here" } |
| 75 |
{ |
| 76 |
int x; // { dg-error "redeclaration of 'int x'" } |
| 77 |
} |
| 78 |
if (int x = 1) |
| 79 |
if (int x = 1) |
| 80 |
; |
| 81 |
if (int x = 0) |
| 82 |
; |
| 83 |
else |
| 84 |
if (int x = 1) |
| 85 |
; |
| 86 |
if (int x = 1) |
| 87 |
switch (int x = 1) |
| 88 |
; |
| 89 |
if (int x = 0) |
| 90 |
while (int x = v) |
| 91 |
; |
| 92 |
if (int x = 0) |
| 93 |
for (int x = v; x; ++x) |
| 94 |
; |
| 95 |
switch (int x = 1) |
| 96 |
switch (int x = 1) |
| 97 |
{ |
| 98 |
case 1:; |
| 99 |
} |
| 100 |
while (int x = 0) |
| 101 |
if (int x = 1) |
| 102 |
; |
| 103 |
for (int x = v; x; ++x) |
| 104 |
for (int x = v; x; ++x) |
| 105 |
; |
| 106 |
} |
| 107 |
|
| 108 |
void |
| 109 |
qux (int x) // { dg-message "'int x' previously declared here" } |
| 110 |
try |
| 111 |
{ |
| 112 |
} |
| 113 |
catch (int x) // { dg-error "declaration of 'int x' shadows a parameter" } |
| 114 |
{ |
| 115 |
} |
| 116 |
|
| 117 |
void |
| 118 |
corge (int x) // { dg-message "'int x' previously declared here" } |
| 119 |
try |
| 120 |
{ |
| 121 |
} |
| 122 |
catch (...) |
| 123 |
{ |
| 124 |
int x; // { dg-error "declaration of 'int x' shadows a parameter" } |
| 125 |
} |
| 126 |
|
| 127 |
void |
| 128 |
fred (int x) // { dg-message "'int x' previously declared here" } |
| 129 |
try |
| 130 |
{ |
| 131 |
} |
| 132 |
catch (int) |
| 133 |
{ |
| 134 |
} |
| 135 |
catch (long) |
| 136 |
{ |
| 137 |
int x; // { dg-error "declaration of 'int x' shadows a parameter" } |
| 138 |
} |
| 139 |
|
| 140 |
void |
| 141 |
garply (int x) |
| 142 |
{ |
| 143 |
try |
| 144 |
{ |
| 145 |
int x; |
| 146 |
} |
| 147 |
catch (...) |
| 148 |
{ |
| 149 |
int x; |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
struct S |
| 154 |
{ |
| 155 |
S (int x) // { dg-message "'int x' previously declared here" } |
| 156 |
try : s (x) |
| 157 |
{ |
| 158 |
int x; // { dg-error "declaration of 'int x' shadows a parameter" } |
| 159 |
} |
| 160 |
catch (...) |
| 161 |
{ |
| 162 |
} |
| 163 |
int s; |
| 164 |
}; |
| 165 |
|
| 166 |
struct T |
| 167 |
{ |
| 168 |
T (int x) // { dg-message "'int x' previously declared here" } |
| 169 |
try : t (x) |
| 170 |
{ |
| 171 |
} |
| 172 |
catch (...) |
| 173 |
{ |
| 174 |
int x; // { dg-error "declaration of 'int x' shadows a parameter" } |
| 175 |
} |
| 176 |
int t; |
| 177 |
}; |
| 178 |
|
| 179 |
struct U |
| 180 |
{ |
| 181 |
U (int x) : u (x) |
| 182 |
{ |
| 183 |
try |
| 184 |
{ |
| 185 |
int x; |
| 186 |
} |
| 187 |
catch (...) |
| 188 |
{ |
| 189 |
int x; |
| 190 |
} |
| 191 |
} |
| 192 |
int u; |
| 193 |
}; |
| 194 |
|
| 195 |
struct V |
| 196 |
{ |
| 197 |
V (int x) : v (x) |
| 198 |
{ |
| 199 |
{ |
| 200 |
int x; |
| 201 |
} |
| 202 |
} |
| 203 |
int v; |
| 204 |
}; |
| 205 |
|
| 206 |
void |
| 207 |
foobar (int x) |
| 208 |
try |
| 209 |
{ |
| 210 |
} |
| 211 |
catch (int) |
| 212 |
{ |
| 213 |
try |
| 214 |
{ |
| 215 |
} |
| 216 |
catch (int x) |
| 217 |
{ |
| 218 |
} |
| 219 |
try |
| 220 |
{ |
| 221 |
} catch (int) |
| 222 |
{ |
| 223 |
int x; |
| 224 |
} |
| 225 |
} |