Skip to content

Copy-construct using initializer-list converts objects to arrays #1359

Description

@arrtchiu

I seem to have hit a bug in either this library / MSVC. Here's a minimal repro case:

struct MyObj {
 json mJson;
 explicit MyObj(json const& input) : mJson{input} {}
};

json j = json::object();
j["foo"] = "bar";
j["baz"] = "ba";
auto x = std::make_shared<MyObj>(j);

std::cout << obj->mJson.dump() << std::endl;

Output:

J: {"baz":"bah","foo":"bar"}
J: [{"baz":"bah","foo":"bar"}]

Interestingly, changing the initialiser from mJson{input} to mJson(input) produces the correct output:

J: {"baz":"bah","foo":"bar"}
J: {"baz":"bah","foo":"bar"}

I'm currently using 3.1.2 but confirmed it also reproduces on latest 3.4.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions