www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - A variation of issue 11977?

reply kdevel <kdevel vogtner.de> writes:
~~~gotoskip.d
int main ()
{
    string[string] aa;
    goto A;               // line 4
    aa["X"] = "Y";        // line 5
A:
    return 0;
}
~~~

$ dmd gotoskip.d
gotoskip.d(4): Error: goto skips declaration of variable 
gotoskip.main.__aaval2 at gotoskip.d(5)

What's wrong here? Only found Issue 11977 [1] in which a 
declaration and
initialization is jumped over. However, the statement in line 5 
is neither
a declaration nor an initialization.

[1] https://issues.dlang.org/show_bug.cgi?id=11977
Jan 21 2021
next sibling parent Paul Backus <snarwin gmail.com> writes:
On Thursday, 21 January 2021 at 13:55:48 UTC, kdevel wrote:
 ~~~gotoskip.d
 int main ()
 {
    string[string] aa;
    goto A;               // line 4
    aa["X"] = "Y";        // line 5
 A:
    return 0;
 }
 ~~~

 $ dmd gotoskip.d
 gotoskip.d(4): Error: goto skips declaration of variable 
 gotoskip.main.__aaval2 at gotoskip.d(5)

 What's wrong here? Only found Issue 11977 [1] in which a 
 declaration and
 initialization is jumped over. However, the statement in line 5 
 is neither
 a declaration nor an initialization.

 [1] https://issues.dlang.org/show_bug.cgi?id=11977
__aaval2 is a compiler-generated temporary variable. If you comment out the `goto A;` (so that the code compiles) and use the compiler flag -vcg-ast, you can see its declaration: int main() { string[string] aa = null; // goto A; (string __aaval2 = "Y";) , aa["X"] = __aaval2; A: return 0; }
Jan 21 2021
prev sibling next sibling parent reply kdevel <kdevel vogtner.de> writes:
On Thursday, 21 January 2021 at 13:55:48 UTC, kdevel wrote:
    goto A;               // line 4
    aa["X"] = "Y";        // line 5
 A:
Creating a scope { aa["X"] = "Y"; } // line 5 works around the issue.
Jan 21 2021
parent z <z z.com> writes:
On Thursday, 21 January 2021 at 14:11:15 UTC, kdevel wrote:
 Creating a scope
 works around the issue.
Another way to work around the issue is to use «asm {jmp label;}» (replace jmp by whatever equivalent is there on the target architecture.) Yes it's ugly, but it bypasses the arbitrary limitation perfectly.
Jan 21 2021
prev sibling parent kdevel <kdevel vogtner.de> writes:
On Thursday, 21 January 2021 at 13:55:48 UTC, kdevel wrote:

[...]

created https://issues.dlang.org/show_bug.cgi?id=21571
Jan 21 2021