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

Another compilation failure with Visual Studio #2007

Closed
garethsb opened this issue Mar 24, 2020 · 6 comments
Closed

Another compilation failure with Visual Studio #2007

garethsb opened this issue Mar 24, 2020 · 6 comments
Labels
kind: bug platform: visual studio related to MSVC state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated

Comments

@garethsb
Copy link
Contributor

garethsb commented Mar 24, 2020

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>>
        ]
@emmenlau
Copy link

emmenlau commented Apr 1, 2020

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

@MarvinSchultz
Copy link

Is there any known workaround?

@bhardwajs
Copy link

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!

@nlohmann nlohmann added the platform: visual studio related to MSVC label Apr 12, 2020
@garethsb
Copy link
Contributor Author

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.

@t-b
Copy link
Contributor

t-b commented Apr 14, 2020

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

@stale
Copy link

stale bot commented May 15, 2020

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.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label May 15, 2020
@stale stale bot closed this as completed May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug platform: visual studio related to MSVC state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated
Projects
None yet
Development

No branches or pull requests

6 participants