Debian Codegraph @

gcc/testsuite/g++.dg/diagnostic/redeclaration-5.C

raw
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 extern int x (int); // { dg-error "declaration of 'int x\\\(int\\\)' shadows a parameter" }
9 }
10
11 void
12 bar (int x) // { dg-message "'int x' previously declared here" }
13 try
14 {
15 extern int x (int); // { dg-error "declaration of 'int x\\\(int\\\)' 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) { extern int x (int); };// { dg-error "declaration of 'int x\\\(int\\\)' 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 extern int x (int); // { dg-error "redeclaration of 'int x\\\(int\\\)'" }
33 }
34 if (int x = 0) // { dg-message "'int x' previously declared here" }
35 ;
36 else
37 {
38 extern int x (int); // { dg-error "redeclaration of 'int x\\\(int\\\)'" }
39 }
40 if (int x = 1) // { dg-message "'int x' previously declared here" }
41 extern int x (int); // { dg-error "redeclaration of 'int x\\\(int\\\)'" }
42 if (int x = 0) // { dg-message "'int x' previously declared here" }
43 ;
44 else
45 extern int x (int); // { dg-error "redeclaration of 'int x\\\(int\\\)'" }
46 switch (int x = 1) // { dg-message "'int x' previously declared here" }
47 {
48 extern int x (int); // { dg-error "redeclaration of 'int x\\\(int\\\)'" }
49 default:;
50 }
51 switch (int x = 1) // { dg-message "'int x' previously declared here" }
52 extern int x (int); // { dg-error "redeclaration of 'int x\\\(int\\\)'" }
53 while (int x = v)
54 {
55 extern int x (int); // { dg-error "'int x\\\(int\\\)' redeclared as different kind of entity" }
56 }
57 while (int x = v)
58 extern int x (int); // { dg-error "'int x\\\(int\\\)' redeclared as different kind of entity" }
59 for (int x = v; x; ++x) // { dg-message "'int x' previously declared here" }
60 {
61 extern int x (int); // { dg-error "redeclaration of 'int x\\\(int\\\)'" }
62 }
63 for (int x = v; x; ++x) // { dg-message "'int x' previously declared here" }
64 extern int x (int); // { dg-error "redeclaration of 'int x\\\(int\\\)'" }
65 for (; int x = v; )
66 {
67 extern int x (int); // { dg-error "'int x\\\(int\\\)' redeclared as different kind of entity" }
68 }
69 for (; int x = v; )
70 extern int x (int); // { dg-error "'int x\\\(int\\\)' redeclared as different kind of entity" }
71 try
72 {
73 }
74 catch (int x) // { dg-message "'int x' previously declared here" }
75 {
76 extern int x (int); // { dg-error "redeclaration of 'int x\\\(int\\\)'" }
77 }
78 }
79
80 void
81 corge (int x) // { dg-message "'int x' previously declared here" }
82 try
83 {
84 }
85 catch (...)
86 {
87 extern int x (int); // { dg-error "declaration of 'int x\\\(int\\\)' shadows a parameter" }
88 }
89
90 void
91 fred (int x) // { dg-message "'int x' previously declared here" }
92 try
93 {
94 }
95 catch (int)
96 {
97 }
98 catch (long)
99 {
100 extern int x (int); // { dg-error "declaration of 'int x\\\(int\\\)' shadows a parameter" }
101 }
102
103 void
104 garply (int x)
105 {
106 try
107 {
108 extern int x (int);
109 }
110 catch (...)
111 {
112 extern int x (int);
113 }
114 }
115
116 struct S
117 {
118 S (int x) // { dg-message "'int x' previously declared here" }
119 try : s (x)
120 {
121 extern int x (int); // { dg-error "declaration of 'int x\\\(int\\\)' shadows a parameter" }
122 }
123 catch (...)
124 {
125 }
126 int s;
127 };
128
129 struct T
130 {
131 T (int x) // { dg-message "'int x' previously declared here" }
132 try : t (x)
133 {
134 }
135 catch (...)
136 {
137 extern int x (int); // { dg-error "declaration of 'int x\\\(int\\\)' shadows a parameter" }
138 }
139 int t;
140 };
141
142 struct U
143 {
144 U (int x) : u (x)
145 {
146 try
147 {
148 extern int x (int);
149 }
150 catch (...)
151 {
152 extern int x (int);
153 }
154 }
155 int u;
156 };
157
158 struct V
159 {
160 V (int x) : v (x)
161 {
162 {
163 extern int x (int);
164 }
165 }
166 int v;
167 };