Is this a bug? +goto

MatheusBN m at gmail.com
Tue Nov 6 02:55:46 UTC 2018


On Tuesday, 6 November 2018 at 01:55:04 UTC, Jonathan M Davis 
wrote:
>> And I found a bit strange that in such code, since "x" is 
>> never used, why it isn't skipped.
>
> It's skipped right over. The goto jumps out of the scope, and 
> the line with
>
> int x;
>
> is never run. In fact, if you compile with -w or -wi, the 
> compiler will give you a warning about unreachable code.

That is exactly my point.

Since "x" it's skipped and never used, it shouldn't just be a 
warning (unreachable code) instead of an error?

I'm trying to understand why/when such code could give any 
problem.

On the other hand if the code were:

{
    goto Q:
    int x;

    Q:
    x = 10; // <- Now you are accessing an uninitialized variable.
}

Then I think an error would be ok.

MatheusBN.


More information about the Digitalmars-d-learn mailing list