What is the issue you have?
crash when traversing over items() of temporary json objects
sometimes got null of pair.value() (https://godbolt.org/z/TTQFHW )
Please describe the steps to reproduce the issue. Can you provide a small but working code example?
const auto obj = nlohmann::json::parse(R"( {
"key1": 0.1,
"key2": 0.2
})" );
auto rvalue = [&]() -> nlohmann::json { return obj; };
for (const auto & pair : rvalue().items()) {
std::cout << pair.key () << " : " << pair.value () << " \n " ; // crash
}
auto crvalue = [&]() -> const nlohmann::json { return obj; };
for (const auto & pair : crvalue().items()) {
std::cout << pair.key () << " : " << pair.value () << " \n " ; // crash
}
What is the expected behavior?
pair.value() returns 0.1 or 0.2
no crash
And what is the actual behavior instead?
crash on my linux machine: json.hpp:14028: void nlohmann::detail::serializer<BasicJsonType>::dump(const BasicJsonType&, bool, bool, unsigned int, unsigned int) [with BasicJsonType = nlohmann::basic_json<>]: Assertion ‘false' failed.
pair.value() returns null on Compiler Explorer. (https://godbolt.org/z/TTQFHW )
linux/centos
gcc 6.2
Did you use a released version of the library or the version from the develop branch?
latest dev branch
release v3.7.3
Reactions are currently unavailable
items()of temporary json objectspair.value()(https://godbolt.org/z/TTQFHW)pair.value()returns0.1or0.2json.hpp:14028: void nlohmann::detail::serializer<BasicJsonType>::dump(const BasicJsonType&, bool, bool, unsigned int, unsigned int) [with BasicJsonType = nlohmann::basic_json<>]: Assertion ‘false' failed.pair.value()returns null on Compiler Explorer. (https://godbolt.org/z/TTQFHW)developbranch?