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.) */
14 for (int i = 0; // { dg-message "previously declared here" "prev" }
17 int i = 2; // { dg-error "redeclaration" "redecl" }
27 int k = j; i++) // { dg-message "previously declared here" "prev" }
29 int k = 2; // { dg-error "redeclaration" "redecl" }
37 if (int i = 1) // { dg-message "previously declared here" "prev" }
39 int i = 2; // { dg-error "redeclaration" "redecl" }
47 if (int i = 1) // { dg-message "previously declared here" "prev" }
53 int i = 2; // { dg-error "redeclaration" "redecl" }
61 while (int i = 1) // { dg-message "previously declared here" "prev" }
63 int i = 2; // { dg-error "redeclaration" "redecl" }
71 switch (int i = j) // { dg-message "previously declared here" "prev" }
73 int i; // { dg-error "redeclaration" "redecl" }
85 for (int i = 0; i < 10; ++i)
89 int i = 2; // OK, not outermost block.
99 for (i = 0; int k = j; i++)
103 int k = 2; // OK, not outermost block.
116 int i = 2; // OK, not outermost block.
133 int i = 2; // OK, not outermost block.
146 int i = 2; // OK, not outermost block.
159 int i = 2; // OK, not outermost block.
170 for (int j = 0; j < 10; j++)
172 int i = 2; // OK, not variable from for-init.