Skip to content

Another compilation failure with Visual Studio #2007

Closed

Description

@garethsb

The following new test case fails to compile with at least Visual Studio 2015 14.0.25431.01 Update 3, and Visual Studio 2019 16.5.0. Related to #167.

#include <nlohmann/json.hpp>
TEST_CASE("JSON pointers")
{
    SECTION("op<<")
    {
        nlohmann::basic_json<std::map, std::vector, std::string, bool, int32_t> a_different_instantiation_of_basic_json;
        nlohmann::json::json_pointer ptr;
        CHECK(ptr == ptr);
    }
}

The error message is:

nlohmann-json\test\thirdparty\doctest\doctest.h(782,1): error C2593: 'operator <<' is ambiguous
nlohmann-json\single_include\nlohmann/json.hpp(20642,26): message : could be 'std::ostream &nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::operator <<(std::ostream &,const nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> &)' [found using argument-dependent lookup]
nlohmann-json\single_include\nlohmann/json.hpp(20642,26): message : or       'std::ostream &nlohmann::basic_json<std::map,std::vector,std::string,bool,int32_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::operator <<(std::ostream &,const nlohmann::basic_json<std::map,std::vector,std::string,bool,int32_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> &)' [found using argument-dependent lookup]
nlohmann-json\test\thirdparty\doctest\doctest.h(782,1): message : while trying to match the argument list '(std::ostream, const T)'
        with
        [
            T=nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>
        ]
nlohmann-json\test\thirdparty\doctest\doctest.h(788): message : see reference to class template instantiation 'doctest::detail::has_insertion_operator_impl::has_insertion_operator<T>' being compiled
        with
        [
            T=nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>
        ]
nlohmann-json\test\thirdparty\doctest\doctest.h(828): message : see reference to class template instantiation 'doctest::detail::has_insertion_operator<T>' being compiled
        with
        [
            T=nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>
        ]
nlohmann-json\test\thirdparty\doctest\doctest.h(854): message : see reference to class template instantiation 'doctest::StringMaker<T>' being compiled
        with
        [
            T=nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>
        ]
nlohmann-json\test\thirdparty\doctest\doctest.h(1011): message : see reference to function template instantiation 'doctest::String doctest::toString<L>(const T &)' being compiled
        with
        [
            L=nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>,
            T=nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>
        ]
nlohmann-json\test\thirdparty\doctest\doctest.h(1159): message : see reference to function template instantiation 'doctest::String doctest::detail::stringifyBinaryExpr<nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>,R>(const L &,const char *,const R &)' being compiled
        with
        [
            R=nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>,
            L=nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>
        ]
nlohmann-json\test\src\foo.cpp(8): message : see reference to function template instantiation 'doctest::detail::Result doctest::detail::Expression_lhs<const nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>> &>::operator ==<nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>>(const R &)' being compiled
        with
        [
            R=nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>
        ]
nlohmann-json\test\src\foo.cpp(8): message : see reference to function template instantiation 'doctest::detail::Result doctest::detail::Expression_lhs<const nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>> &>::operator ==<nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>>(const R &)' being compiled
        with
        [
            R=nlohmann::json_pointer<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>
        ]

Activity

  1. emmenlau commented on Apr 1, 2020

    @emmenlau

    Yep, we get the same problem after switching from VS2019.3 to VS2019.5.

  2. MarvinSchultz commented on Apr 8, 2020

    @MarvinSchultz

    Is there any known workaround?

  3. subhardw commented on Apr 11, 2020

    @subhardw

    Just spent couple of hours on this issue and I can confirm I have a repro. I don't have a good reason why this is happening. Let me invest more time over the weekend and next week and see I can figure out why ADL is making this break.

    As for workaround @MarvinSchultz , this compiled for me:

     SECTION("op<<")
        {
            nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t> a_different_instantiation_of_basic_json;
            nlohmann::json::json_pointer ptr;
            CHECK(ptr == ptr);
        }
    

    Does this work for you? I am running VS 16.5.3 and cl.exe 19.25.28612.0.

    If there is another MSVC issue, please do tag me. Thank you!

  4. garethsb commented on Apr 14, 2020

    @garethsb
    ContributorAuthor

    That "workaround" isn't really a workaround, really, because by changing int32_t to int64_t, the type a_different_instantiation_of_basic_json is not actually different.

  5. t-b commented on Apr 14, 2020

    @t-b
    Contributor

    How about adding a PR with that new test case and then we can check which compilers accept that and which not?

  6. stale commented on May 15, 2020

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  7. added
    state: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated
    on May 15, 2020
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

    kind: bugplatform: visual studiorelated to MSVCstate: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions