Shao Miller said:
How do you "undeclare" the identifier(s) in the 'while' version, after
the 'while' statement, so as to free up storage? Do you _need_ to
free the storage for the identifier(s) in the 'for' version?
I don't think these questions help. I think the difference in opinion
may come from the interpretation of a footnote. We both agree that the
scope of a for-loop-declared VLA object extends from the declaration to
the end of the controlled statement (that's your first cited
paragraph). The second citation says:
For such an object [of automatic storage duration] that does have a
variable length array type, its lifetime extends from the declaration
of the object until execution of the program leaves the scope of the
declaration.[27]
Footnote 27 is about what it means to leave the scope:
[27] Leaving the innermost block containing the declaration, or
jumping to a point in that block or an embedded block prior to
the declaration, leaves the scope of the declaration.
Presumably you take falling out of the for loop as "leaving the scope"
but that does not fit the wording of the footnote.
Maybe falling out of the scope *is* "leaving the scope" (i.e. maybe
footnote 27 is there to illustrate a couple of possibilities, rather
than explain the term). I agree that that's perfectly reasonable, but
there are other cases where going from being in the scope to not being
in it is not the same as leaving it (function calls for example).
On your side, there is evidence that even if footnote 27 is intended to
explain the term, it might simply fail to consider the case of
identifiers declared in for loops. The evidence being that that occurs
elsewhere. For example, 6.4.1p4 says:
If the declarator or type specifier that declares the identifier
appears inside a block or within the list of parameter declarations in
a function definition, the identifier has block scope, which
terminates at the end of the associated block.
Presumably, 6.8.5.3p1 refines this statement, but it would be better if
the above at least mentioned the case of a for loop.
I am leaning you way here. I suspect the footnote 27 just lists a
couple of possibilities and the natural meaning of "leaving the scope"
applies here, but I am glad it's a debate about a useless case.
<snip>