Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse an object but get an array using GCC #3076

Closed
SlavaMelanko opened this issue Oct 12, 2021 · 1 comment
Closed

Parse an object but get an array using GCC #3076

SlavaMelanko opened this issue Oct 12, 2021 · 1 comment
Labels
kind: bug solution: duplicate the issue is a duplicate; refer to the linked issue instead

Comments

@SlavaMelanko
Copy link

I will start with an example:

class Doc
{
public:
    explicit Doc(const std::string &data)
        : m_doc{nlohmann::json::parse(data)}
    {}

    auto dump() const { return m_doc.dump(); }

private:
    nlohmann::json m_doc;
};

int main()
{
    const std::string data{R"({"value": 1})"};

    auto v = nlohmann::json::parse(data);
    std::cout << v.dump() << std::endl; // {"value":1}

    Doc d{data};
    std::cout << d.dump() << std::endl; // [{"value":1}]

    return 0;
}

Link for compiler explorer

Probably I missed something, but why do I always get an array in the second case using GCC? Clang is ok.

Expected behavior: output must be {"value":1} twice.

Environment:

  • I checked on GCC 9 and above
  • Json library the latest releases
@nlohmann
Copy link
Owner

Duplicate of #2583.

@nlohmann nlohmann added the solution: duplicate the issue is a duplicate; refer to the linked issue instead label Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug solution: duplicate the issue is a duplicate; refer to the linked issue instead
Projects
None yet
Development

No branches or pull requests

2 participants