The statement in stmt.stmt#stmt.pre-5 explicitly says:
[Note 2: A name introduced in a selection-statement or iteration-statement outside of any substatement is in scope from its point of declaration until the end of the statement’s substatements. Such a name cannot be redeclared in the outermost block of any of the substatements ([basic.scope.block]). — end note]
The key term here is outermost block which is defined in stmt.block#1:
A compound statement (also known as a block) groups a sequence of statements into a single statement.
compound-statement:
{ statement-seq opt }
…
A compound statement defines a block scope.
So stmt.stmt#stmt.pre-5 is essentially saying:
if (int a = 0)
{ // outermost block
int a; // so ill-formed
}
but
if (int a = 0)
{ // outermost block
{ // inner block
int a; // so well-formed
}
}
The same rules apply in your example with the block introduced by the nested if
statement.
CLICK HERE to find out more related problems solutions.