json icon indicating copy to clipboard operation
json copied to clipboard

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

Open not-a-user opened this issue 6 years ago • 2 comments

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.

not-a-user avatar Aug 24 '20 21:08 not-a-user

Duplicate of #2311.

nlohmann avatar Aug 25 '20 07:08 nlohmann

Duplicate of #2311.

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

not-a-user avatar Aug 25 '20 08:08 not-a-user