www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19256] New: std.json: JSONValue allows violating constness


          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 puremagic.com
          Reporter: default_357-line 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.

Sep 21 2018