www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13295] New: [CTFE] Modifications of const user type disappear

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

          Issue ID: 13295
           Summary: [CTFE] Modifications of const user type disappear
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: CTFE, wrong-code
          Severity: major
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: verylonglogin.reg gmail.com

This code should compile fine:
---
struct S
{
    int n;
}

void f(ref const S s)
{
    *cast(int*) &s.n = 1;
//  assert(s.n == 1);     // will also fail
}

void main()
{
    static assert(
    {
        S s;
        f(s);
        return s.n == 1; // false, s.n is 0
    } ());
}
---

--
Aug 15 2014