[Issue 19256] New: std.json: JSONValue allows violating constness

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 21 08:50:32 UTC 2018


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

          Issue ID: 19256
           Summary: std.json: JSONValue allows violating constness
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: default_357-line at yahoo.de

Consider the following code:

import std.json;

@safe unittest {
    const JSONValue innerObj = JSONValue(["foo": JSONValue(1)]);

    assert(innerObj["foo"] == JSONValue(1));

    // Why can I do this??
    JSONValue value = innerObj;

    value["foo"] = JSONValue(2);

    assert(innerObj["foo"] == JSONValue(1));
}

innerObj is changed, even though we access it through a const variable.

This should not be allowed.

--


More information about the Digitalmars-d-bugs mailing list