json
json copied to clipboard
Assert when using std::views::filter and GCC 10
Description
After upgrading from 3.9.1
to 3.11.3
the code asserts when iterating over a json array that's been filtered using std::views::filter
due to an uninitialized iterator.
In addition to my failure with 3.11.3 and GCC 10.2, I checked other combinations on Godbolt and observed the following (❌ represents the assert is seen)
GCC 10.2 | GCC 10.5 | GCC 11.1 | GCC trunk | Clang 16 | |
---|---|---|---|---|---|
3.9.1 | ✅ | ✅ | ✅ | ✅ | ✅ |
3.10.5 | ✅ | ✅ | ✅ | ✅ | ✅ |
3.11.1 | ❌ | ❌ | ❌ | ✅ | ✅ |
trunk | ❌ | ❌ | ❌ | ✅ | ✅ |
Reproduction steps
https://godbolt.org/z/WbexYTqnf
Expected vs. actual results
std::views::filter
should allow you to filter a json array.
Minimal code example
#include <nlohmann/json.hpp>
#include <iostream>
#include <ranges>
using nlohmann::json;
int main()
{
auto noOpFilter = std::views::filter([](auto&&){ return true; });
json j = {1, 2, 3};
auto filtered = j | noOpFilter;
std::cout << *filtered.begin() << std::endl;
return 0;
}
Error messages
output.s: /opt/compiler-explorer/libs/nlohmann_json/trunk/single_include/nlohmann/json.hpp:13346: bool nlohmann::json_abi_v3_11_3::detail::iter_impl<BasicJsonType>::operator==(const IterImpl&) const [with IterImpl = nlohmann::json_abi_v3_11_3::detail::iter_impl<nlohmann::json_abi_v3_11_3::basic_json<> >; typename std::enable_if<(std::is_same<IterImpl, nlohmann::json_abi_v3_11_3::detail::iter_impl<BasicJsonType> >::value || std::is_same<IterImpl, nlohmann::json_abi_v3_11_3::detail::iter_impl<typename std::conditional<std::is_const<_Tp>::value, typename std::remove_const<_Tp>::type, const BasicJsonType>::type> >::value), std::nullptr_t>::type <anonymous> = nullptr; BasicJsonType = nlohmann::json_abi_v3_11_3::basic_json<>]: Assertion `m_object != nullptr' failed.
Program terminated with signal: SIGSEGV
Compiler and operating system
GCC 10.2
Library version
3.11.3
Validation
- [X] The bug also occurs if the latest version from the
develop
branch is used. - [X] I can successfully compile and run the unit tests.