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

ambiguous conversion with nlohmann-json 3.10.4 #5923

Closed
thkoch2001 opened this issue Jan 16, 2022 · 3 comments · Fixed by #5943
Closed

ambiguous conversion with nlohmann-json 3.10.4 #5923

thkoch2001 opened this issue Jan 16, 2022 · 3 comments · Fixed by #5943
Labels

Comments

@thkoch2001
Copy link
Contributor

thkoch2001 commented Jan 16, 2022

I'm working on an update for the nix Debian package to 2.5.1. In Debian we try to avoid vendorized code, thus I use the already packaged nlohmann-json3 in version 3.10.4.

The nlohmann-json version in nix seems to be 3.9.1.

I see this compilation error:

src/libstore/realisation.cc: In lambda function:                                                                                                                     [14/9368]
src/libstore/realisation.cc:81:16: error: conversion from ‘const nlohmann::basic_json<>’ to ‘std::optional<std::__cxx11::basic_string<char> >’ is ambiguous
   81 |         return *fieldIterator;
      |                ^~~~~~~~~~~~~~
In file included from src/libstore/realisation.cc:4:
/usr/include/nlohmann/json.hpp:3413:55: note: candidate: ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFl
oatType, AllocatorType, JSONSerializer, BinaryType>::operator ValueType() const [with ValueType = std::optional<std::__cxx11::basic_string<char> >; typename std::enable_if<nl
ohmann::detail::conjunction<nlohmann::detail::negation<std::is_pointer<_Ptr> >, nlohmann::detail::negation<std::is_same<ValueType, nlohmann::detail::json_ref<nlohmann::basic_
json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType> > > >, nlohmann::detai
l::negation<std::is_same<ValueType, typename StringType::value_type> >, nlohmann::detail::negation<nlohmann::detail::is_basic_json<BasicJsonType> >, nlohmann::detail::negatio
n<std::is_same<ValueType, std::initializer_list<typename StringType::value_type> > >, nlohmann::detail::negation<std::is_same<ValueType, std::basic_string_view<char, std::cha
r_traits<char> > > >, nlohmann::detail::is_detected_lazy<nlohmann::detail::get_template_function, const nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, N
umberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>&, ValueType> >::value, int>::type <anonymous> = 0; ObjectType = std::map; Ar
rayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatTyp
e = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer; BinaryType = std::vector<unsigned char>]’
 3413 |                                         JSON_EXPLICIT operator ValueType() const
      |                                                       ^~~~~~~~
In file included from src/libutil/error.hh:11,
                 from src/libutil/util.hh:4,
                 from src/libutil/serialise.hh:6,
                 from src/libutil/hash.hh:4,
                 from src/libstore/content-address.hh:4,
                 from src/libstore/path.hh:3,
                 from src/libstore/realisation.hh:3,
                 from src/libstore/realisation.cc:1:
/usr/include/c++/11/optional:704:9: note: candidate: ‘constexpr std::optional<_Tp>::optional(_Up&&) [with _Up = const nlohmann::basic_json<>&; typename std::enable_if<__and_v
<std::__not_<std::is_same<std::optional<_Tp>, typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type> >, std::__not_<std::is_same<std::in_place_t, typename
std::remove_cv<typename std::remove_reference<_Tp>::type>::type> >, std::is_constructible<_Tp, _Up>, std::is_convertible<_Up, _Tp> >, bool>::type <anonymous> = true; _Tp = st
d::__cxx11::basic_string<char>]’
  704 |         optional(_Up&& __t)
      |         ^~~~~~~~
make[1]: *** [mk/patterns.mk:3: src/libstore/realisation.o] Error 1

I'm not a C++ programmer, so please don't laugh. I'd guess that one would simply need to tell the compiler, which conversion to use?

This is the code in question from src/libstore/realisation.cc#L81:

    auto getOptionalField = [&](std::string fieldName) -> std::optional<std::string> {
        auto fieldIterator = json.find(fieldName);
        if (fieldIterator == json.end())
            return std::nullopt;
        return *fieldIterator;
    };

Is this related? nlohmann/json#3204

@thkoch2001 thkoch2001 added the bug label Jan 16, 2022
@thkoch2001
Copy link
Contributor Author

I tried compilation now with nlohmann version 3.9.1 from Debian and this error did not appear anymore. Version 3.10.5 of nlohmann-json3 has been uploaded to Debian unstable today and I'll test this one and report back.

@thkoch2001
Copy link
Contributor Author

If you came here because you care about the nix Debian package, then please also look at #5931

@thkoch2001
Copy link
Contributor Author

Unfortunately the problem still persists with version 3.10.5 of nlohmann-json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant