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

Assert when using std::views::filter and GCC 10 #4440

Open
2 tasks done
gwjo opened this issue Aug 23, 2024 · 0 comments
Open
2 tasks done

Assert when using std::views::filter and GCC 10 #4440

gwjo opened this issue Aug 23, 2024 · 0 comments

Comments

@gwjo
Copy link

gwjo commented Aug 23, 2024

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

@gwjo gwjo added the kind: bug label Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant