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

Unexpected array when initializing a json const& on gcc 4.8.5 using uniform syntax #2370

Closed
not-a-user opened this issue Aug 24, 2020 · 2 comments
Labels
kind: bug solution: duplicate the issue is a duplicate; refer to the linked issue instead

Comments

@not-a-user
Copy link

not-a-user commented Aug 24, 2020

Minimal example:

#include "json.hpp" // 3.9.1
#include <cassert>
#include <iostream>

using namespace nlohmann;
using namespace std;

int main()
{
        json const j = "{\"key\": null}"_json;
        assert(j.is_object());
        json const& k{j.at("key")};
        cout << k << endl;
        assert(k.is_null());
}

Fails on gcc 4.8.5 with -std=c++0x:

[null]
minimal: minimal.cpp:14: int main(): Assertion `k.is_null()' failed.

Note that k refers to an array, so at() has made a copy though j is const. Don't know if you keep track of that copy via some mutable or if there is a segfault ahead because of a dangling reference.

Passes on more recent gcc.

@nlohmann
Copy link
Owner

Duplicate of #2311.

@nlohmann nlohmann added the solution: duplicate the issue is a duplicate; refer to the linked issue instead label Aug 25, 2020
@not-a-user
Copy link
Author

Duplicate of #2311.

Sure? This affects only older gcc. It really messes badly with the reference initialization.

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