Skip to content

Ambiguous function call to get with pointer type and constant json object in VS2015 (15.4.4) #852

Description

@MaxSavenkov

This code will not compile in Visual Studio 2015 (15.4.4) with the latest nlohmann::json code:

    const nlohmann::json test;
    const auto *s = test.get<const std::string*>();

The error message is:

1>F:\rolecraft2\prj\rolecraft\ui\ui_view_character.cpp(13): error C2668: 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get': ambiguous call to overloaded function
1>F:\rolecraft2\ext\nlohmann\json.hpp(9669): note: could be 'const PointerType nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get<const std::string*,0>(void) noexcept const'
1>        with
1>        [
1>            PointerType=const std::string *
1>        ]
1>F:\rolecraft2\ext\nlohmann\json.hpp(9657): note: or       'PointerType nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get<const std::string*,0>(void) noexcept'
1>        with
1>        [
1>            PointerType=const std::string *
1>        ]
1>F:\rolecraft2\ext\nlohmann\json.hpp(9567): note: or       'ValueType nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get<const std::string*,const std::string*,0>(void) noexcept(<expr>) const'
1>        with
1>        [
1>            ValueType=const std::string *
1>        ]

Seems like Visual Studio's compiler can't decide whether to use ValueType version of get(), or PointerType one. The issue is easily worked around by using get_ptr() instead, but I still would like to report it, as it was working in older versions of the library (2.0.5, for example).

The issue can be fixed by adding

            not std::is_pointer<ValueType>::value and

to enable_if template of ValueType get() const noexcept method.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions