www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17387] New: static struct this(ref) not pure

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

          Issue ID: 17387
           Summary: static struct this(ref) not pure
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: nick geany.org

struct S { this(ref int val) { ++val; } }

pure unittest
{
    int val = 3;
    auto s = S(val);
    assert(val == 4);
}

The above fails to compile with dmd v2.074.0:
purestaticstruct.d(6): Error: pure function 'purestaticstruct.__unittestL3_1'
cannot call impure constructor 'purestaticstruct.S.this'

If the struct is moved inside the unittest, it compiles as expected.

--
May 09