[Issue 24534] New: Having a label on a declaration makes it possible to skip it with goto
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Fri May  3 20:42:42 UTC 2024
    
    
  
https://issues.dlang.org/show_bug.cgi?id=24534
          Issue ID: 24534
           Summary: Having a label on a declaration makes it possible to
                    skip it with goto
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: issues.dlang at jmdavisProg.com
This code compiles and runs:
---
void main()
{
     int x;
     goto Label;
     Dummy:
     int y;
     Label:
     int z;
     import std.stdio;
     writeln(y);
}
---
The value of y is then garbage (e.g. 539662115), because the declaration for y
was skipped, and it wasn't actually initialized. On the other hand, if the
Dummy label is removed, then we get an error such as
---
q.d(4): Error: `goto` skips declaration of variable `q.main.y`
q.d(5):        declared here
---
So, it would appear that the label on the variable is confusing the compiler
and causing it to not understand that a declaration has been skipped.
--
    
    
More information about the Digitalmars-d-bugs
mailing list