You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
from_json not working for boost::optional example #718
Does your code compile? Your snippet might not be complete, since I had to change the code to nlohmann::json j{{"test", nullptr}} and I get a compiler error.
Yes, that's the code that's failing for me on Mac with XCode 8.3.3 and Boost 1.64. It seems to be an issue with Apple's version of Clang. I tried reproducing this using wandbox.org by changing the compiler version and I get the compiler error like you with every version of Clang they have. The problem here is that Apple ships a custom version of Clang that we know nothing about and they obviously diverged in behaviour (or it's a command line switch I'm unaware of)...
On OSX, I also can't compile the code. GCC and Clang (all with different versions) agree on this error:
In file included from /usr/local/include/boost/optional.hpp:15:
/usr/local/include/boost/optional/optional.hpp:315:12: error: call to member function 'construct' is ambiguous
else construct(boost::forward<Expr>(expr),tag);
^~~~~~~~~
/usr/local/include/boost/optional/optional.hpp:904:15: note: in instantiation of function template specialization
'boost::optional_detail::optional_base<int>::assign_expr<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long
long, unsigned long long, double, std::allocator, adl_serializer> &, nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>,
bool, long long, unsigned long long, double, std::allocator, adl_serializer> >' requested here
this->assign_expr(boost::forward<Expr>(expr),boost::addressof(expr));
^
op.cpp:35:10: note: in instantiation of function template specialization 'boost::optional<int>::operator=<nlohmann::basic_json<std::map, std::vector,
std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer> &>' requested here
broken = json["test"];
^
/usr/local/include/boost/optional/optional.hpp:367:10: note: candidate function [with Args = <const nlohmann::basic_json<std::map, std::vector,
std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer> *&>]
void construct ( in_place_init_t, Args&&... args )
^
/usr/local/include/boost/optional/optional.hpp:616:10: note: candidate function [with Expr = nlohmann::basic_json<std::map, std::vector,
std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer> &]
void construct ( Expr&& expr, void const* )
^
/usr/local/include/boost/optional/optional.hpp:546:10: note: candidate function [with Expr = nlohmann::basic_json<std::map, std::vector,
std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer> &] not viable: no known conversion from
'const nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator,
adl_serializer> *' to 'const boost::in_place_factory_base *' for 2nd argument
void construct ( Expr&& factory, in_place_factory_base const* )
^
/usr/local/include/boost/optional/optional.hpp:554:10: note: candidate function [with Expr = nlohmann::basic_json<std::map, std::vector,
std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer> &] not viable: no known conversion from
'const nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator,
adl_serializer> *' to 'const boost::typed_in_place_factory_base *' for 2nd argument
void construct ( Expr&& factory, typed_in_place_factory_base const* )
^
/usr/local/include/boost/optional/optional.hpp:355:10: note: candidate function not viable: requires single argument 'val', but 2 arguments were
provided
void construct ( rval_reference_type val )
^
/usr/local/include/boost/optional/optional.hpp:348:10: note: candidate function not viable: requires single argument 'val', but 2 arguments were
provided
void construct ( argument_type val )
^
1 error generated.
It's the boost version, not the compiler, sorry for the wild goose chase. This only happens with boost 1.56 and is not that relevant in my view, it'll get resolved as we moved to latest version of boost. I'm happy for you to close this bug.
Activity
theodelrieu commentedon Aug 29, 2017
Does your code compile? Your snippet might not be complete, since I had to change the code to
nlohmann::json j{{"test", nullptr}}and I get a compiler error.This is because
boost::optionalhas multiple overloads ofoperator=, we updated the Readme (some important things section) to warn about this issue.popizdeh commentedon Aug 29, 2017
Sorry about that, I've modified the snippet. I'd be happy if the code didn't compile but it fails at runtime which I think is really bad.
theodelrieu commentedon Aug 29, 2017
Here is my full file:
I still got the same compiler error, which boost version are you using? I have 1.64 on Debian 8 x64
popizdeh commentedon Aug 30, 2017
Yes, that's the code that's failing for me on Mac with XCode 8.3.3 and Boost 1.64. It seems to be an issue with Apple's version of Clang. I tried reproducing this using wandbox.org by changing the compiler version and I get the compiler error like you with every version of Clang they have. The problem here is that Apple ships a custom version of Clang that we know nothing about and they obviously diverged in behaviour (or it's a command line switch I'm unaware of)...
nlohmann commentedon Aug 30, 2017
On OSX, I also can't compile the code. GCC and Clang (all with different versions) agree on this error:
popizdeh commentedon Aug 30, 2017
It's the boost version, not the compiler, sorry for the wild goose chase. This only happens with boost 1.56 and is not that relevant in my view, it'll get resolved as we moved to latest version of boost. I'm happy for you to close this bug.
Thanks for the quick responses everyone.
nlohmann commentedon Aug 30, 2017
Ok. Thanks for checking back!