www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18562] New: expression is not evaluated when accessing

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

          Issue ID: 18562
           Summary: expression is not evaluated when accessing manifest
                    constant
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: default_357-line yahoo.de

Consider:

struct Struct
{
    enum Enum = 5;
}

Struct foo()
{
    while (true) { }
    return Struct();
}

void main()
{
    auto value = foo().Enum;
    assert(false);
}

The assert trips, despite the fact that foo() should loop indefinitely, because
the compiler optimizes away the call to foo entirely. This is highly


Is this really intended?

--
Mar 06 2018