www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13815] New: Inconsistent goto jump behavior between

https://issues.dlang.org/show_bug.cgi?id=13815

          Issue ID: 13815
           Summary: Inconsistent goto jump behavior between compile-time
                    and runtime
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: CTFE
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: k.hara.pg gmail.com

Following code behaves differently in compile-time and runtime.

bool f()
{
    goto L;
    try
    {
L:                                  // line 7
        throw new Exception("");    // line 8
    }
    catch (Exception e)
    {
        return true;
    }
    return false;
}
static assert(f());

void main()
{
    f();
}

If you compile the code, CTFEing f() will raise compile-time errors:

test.d(8): Error: Uncaught CTFE exception object.Exception("")
test.d(16):        called from here: f()
test.d(16):        while evaluating: static assert(f())

But, if you mask the static assert, codegen for the function will report a
glue-layer error:

test.d(7): Error: cannot goto into try block

--
Dec 03 2014