* auto-profile.c (afdo_annotate_cfg): Use update_max_bb_count.
[official-gcc.git] / gcc / testsuite / g++.dg / parse / pr18770.C
blob71d95e331134ac01b64a985c582a28f791fb1c7b
1 /* { dg-do compile } */
3 /* The ISO C++ standard says, in Section 3.3.2 sentence 4, that a name
4    declared in the for-init-statement or in the condition of an if, for
5    while, or switch statement can't be redeclared in the outermost block
6    of the controlled statement.  (Note, this is not an error in C.)  */
8 extern void foo (int);
9 extern int j;
11 void
12 e0 (void)
14   for (int i = 0;       // { dg-message "previously declared here" "prev" }
15        i < 10; ++i)
16     {
17       int i = 2;        // { dg-error "redeclaration" "redecl" }
18       foo (i);
19     }
22 void
23 e1 (void)
25   int i;
26   for (i = 0;
27        int k = j; i++)  // { dg-message "previously declared here" "prev" }
28     {
29       int k = 2;        // { dg-error "redeclaration" "redecl" }
30       foo (k);
31     }
34 void
35 e2 (void)
37   if (int i = 1)        // { dg-message "previously declared here" "prev" }
38     {
39       int i = 2;        // { dg-error "redeclaration" "redecl" }
40       foo (i);
41     }
44 void
45 e3 (void)
47   if (int i = 1)        // { dg-message "previously declared here" "prev" }
48     {
49       foo (i);
50     }
51   else
52     {
53       int i = 2;        // { dg-error "redeclaration" "redecl" }
54       foo (i);
55     }
58 void
59 e4 (void)
61   while (int i = 1)     // { dg-message "previously declared here" "prev" }
62     {
63       int i = 2;        // { dg-error "redeclaration" "redecl" }
64       foo (i);
65     }
68 void
69 e5 (void)
71   switch (int i = j)    // { dg-message "previously declared here" "prev" }
72     {
73     int i;              // { dg-error "redeclaration" "redecl" }
74     default:
75       {
76         i = 2;
77         foo (i);
78       }
79     }
82 void
83 f0 (void)
85   for (int i = 0; i < 10; ++i)
86     {
87       foo (i);
88       {
89         int i = 2;      // OK, not outermost block.
90         foo (i);
91       }
92     }
95 void
96 f1 (void)
98   int i;
99   for (i = 0; int k = j; i++)
100     {
101       foo (k);
102       {
103         int k = 2;      // OK, not outermost block.
104         foo (k);
105       }
106     }
109 void
110 f2 (void)
112   if (int i = 1)
113     {
114       foo (i);
115       {
116         int i = 2;      // OK, not outermost block.
117         foo (i);
118       }
119     }
122 void
123 f3 (void)
125   if (int i = 1)
126     {
127       foo (i);
128     }
129   else
130     {
131       foo (i+2);
132       {
133         int i = 2;      // OK, not outermost block.
134         foo (i);
135       }
136     }
139 void
140 f4 (void)
142   while (int i = 1)
143     {
144       foo (i);
145       {
146         int i = 2;      // OK, not outermost block.
147         foo (i);
148       }
149     }
152 void
153 f5 (void)
155   switch (int i = j)
156     {
157     default:
158       {
159         int i = 2;      // OK, not outermost block.
160         foo (i);
161       }
162     }
165 void
166 f6 (void)
168   int i = 1;
170   for (int j = 0; j < 10; j++)
171     {
172       int i = 2;        // OK, not variable from for-init.
173       foo (i);
174     }