https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93844

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> Guess it's the same bug as with C99 or C++ where you can write
> 
> const char *st = "Shall we?";
> int main()
> {
>   printf ("%s\n", st);
>   printf ("%s\n", "Before assignment");
>   const char *st = "Hello, world!";
>   printf ("%s\n", st);
>   return 0;
> }
> 

AFAIU, the go language rules define the scope of the variable to start at the
variable declaration ( https://golang.org/ref/spec#Declarations_and_scope ):
...
The scope of a constant or variable identifier declared inside a function
begins at the end of the ConstSpec or VarSpec (ShortVarDecl for short variable
declarations) and ends at the end of the innermost containing block.
...

For C++, things are well-defined in terms of declarative region, potential
scope, actual scope and point of declaration.

[ FWIW, for C99, I can't actually find a clear interpretation of the program in
the standard. That is, it's defined that the local variable has block scope,
and that the block scope ends at the end of the associated block. But it's not
defined where the block scope starts. If we interpret the block scope to start
at the start of the block, then the compiler should emit a use-before-declare
error. But I'm guessing I'm missing something. ]

So agreed, it's the same bug, at least for C++.

Reply via email to