Wait! Don't answer that. Not before considering this:
if/switch/while/for statements, that's pretty common stuff, no weird templated code involved. Both compilers should be able to handle them as stated, right ?C++ 6.4p1 (selection-statements):
selection-statement:
if ( condition ) statement
if ( condition ) statement else statement
switch ( condition ) statement
C++ 6.4p2:
The rules for conditions apply both to selection-statements and to the for and while statements
C++ 6.4p3:
A name introduced by a declaration in a condition is in scope from its point of declaration until the end of the substatements controlled by the condition. If the name is re-declared in the outermost block of a substatement controlled by the condition, the declaration that re-declares the name is ill-formed.
Example:Code: Select all
if (int x = f()) { int x; // ill-formed, redeclaration of x } else { int x; // ill-formed, redeclaration of x }
Let's see...
VC++
Code: Select all
int f();
void g() {
if (int x=f()) {
int x; // error, PASS
}
switch (int x=f()) {
default:
int x; // no error, FAIL
}
while (int x=f()) {
int x; // error, PASS
}
for (;int x=f();) {
int x; // error, PASS
}
}GCC
Code: Select all
int f();
void g() {
if (int x=f()) {
int x; // no error, FAIL
}
switch (int x=f()) {
default:
int x; // no error, FAIL
}
while (int x=f()) {
int x; // error, PASS
}
for (;int x=f();) {
int x; // error, PASS
}
}And there's more...
Let's do some tests..C++ 6.5.3p1 (The for statement)
The for statement:
for ( for-init-statement condition[optinal] ; expression[optional] ) statement
Names declared in the for-init-statement are in the same declarative-region as those declared in the condition.
VC++
Code: Select all
int f();
void g() {
for (int x; int x=f();) {} // redeclaration error, PASS
}Code: Select all
int f();
void g() {
for (int x; int x=f();) {} // no error, FAIL
}VC++: 4 PASS, 1 FAIL
GCC: 2 PASS, 3 FAIL
And the round goes to.. VC++

