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

[MSVC][std:c++latest] JSON failed with error C2678: binary '==': no operator found which takes a left-hand operand of type 'nlohmann::json_abi_v3_11_2::json' #3868

Open
1 of 2 tasks
QuellaZhang opened this issue Dec 7, 2022 · 4 comments
Labels
kind: bug state: help needed the issue needs help to proceed

Comments

@QuellaZhang
Copy link

QuellaZhang commented Dec 7, 2022

Description

After the MSVC team implemented P2468R2 The Equality Operator You Are Looking For, we got compiler errors with /std:c++latest like below. The way this fails is that the != operator here: https://github.com/nlohmann/json/blob/develop/include/nlohmann/json.hpp#L3704 actually suppresses the rewritten operator candidates and stops the code from compiling because the rewritten candidates are discarded. Could you please look this issue? Thanks.

Note: this issue will be reproduced on next release version of VS(17.6 or later).

Reproduction steps

  1. open VS2019 x64 tools command (Or VS2022)
  2. git clone https://github.com/nlohmann/json F:\gitP\nlohmann\json
  3. mkdir F:\gitP\nlohmann\json\build_amd64
  4. cd F:\gitP\nlohmann\json\build_amd64
  5. cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.18362.0 -DJSON_BuildTests=On ..
  6. set CL= /std:c++latest
  7. msbuild /m /p:Platform=x64 /p:Configuration=Release nlohmann_json.sln /t:Rebuild

Expected vs. actual results

Expected Result:
The build was successful.

Actual Result:
build.log: JSON_amd64_build.log

unit-constructor1.cpp
F:\gitP\nlohmann\json\tests\src\unit-constructor1.cpp(282,13): error C2088: '==': illegal for class

unit-iterators2.cpp
F:\gitP\nlohmann\json\tests\src\unit-iterators2.cpp(946,17): error C2678: binary '==': no operator found which takes a left-hand operand of type 'nlohmann::json_abi_v3_11_2::json' (or there is no acceptable conversion)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\thread(242,36): note: could be 'bool std::operator ==(std::thread::id,std::thread::id) noexcept' [found using argument-dependent lookup]
F:\gitP\nlohmann\json\include\nlohmann/json.hpp(3680,10): note: or 'bool nlohmann::json_abi_v3_11_2::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::json_abi_v3_11_2::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>,void>::operator ==(const nlohmann::json_abi_v3_11_2::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::json_abi_v3_11_2::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>,void> &) noexcept const' [synthesized expression 'y == x']
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\thread(242,36): note: or 'bool std::operator ==(std::thread::id,std::thread::id) noexcept' [synthesized expression 'y == x']
F:\gitP\nlohmann\json\tests\thirdparty\doctest\doctest.h(1238,9): note: or       'unknown-type doctest::detail::Expression_lhs<std::ranges::reverse_view<std::ranges::ref_view<nlohmann::json_abi_v3_11_2::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::json_abi_v3_11_2::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>,void>>> &>::operator ==(R &&)'
F:\gitP\nlohmann\json\tests\src\unit-iterators2.cpp(946,17): note: Failed to specialize function template 'unknown-type doctest::detail::Expression_lhs<std::ranges::reverse_view<std::ranges::ref_view<nlohmann::json_abi_v3_11_2::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::json_abi_v3_11_2::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>,void>>> &>::operator ==(R &&)'
F:\gitP\nlohmann\json\tests\src\unit-iterators2.cpp(946,17): note: With the following template arguments:
F:\gitP\nlohmann\json\tests\src\unit-iterators2.cpp(946,17): note: 'R=nlohmann::json_abi_v3_11_2::json &'
F:\gitP\nlohmann\json\include\nlohmann/json.hpp(3697,10): note: or 'bool nlohmann::json_abi_v3_11_2::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::json_abi_v3_11_2::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>,void>::operator ==(ScalarType) noexcept const' [synthesized expression 'y == x']
F:\gitP\nlohmann\json\tests\src\unit-iterators2.cpp(946,17): note: the associated constraints are not satisfied
F:\gitP\nlohmann\json\include\nlohmann/json.hpp(3696,14): note: the constraint was not satisfied
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\utility(367,27): note: or       'bool std::operator ==(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)'
F:\gitP\nlohmann\json\tests\src\unit-iterators2.cpp(946,17): note: 'bool std::operator ==(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)': could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 
F:\gitP\nlohmann\json\tests\src\unit-iterators2.cpp(946,17): error C2660: 'doctest::detail::decomp_assert': function does not take 4 arguments
F:\gitP\nlohmann\json\tests\thirdparty\doctest\doctest.h(1425,28): note: see declaration of 'doctest::detail::decomp_assert'
F:\gitP\nlohmann\json\tests\src\unit-iterators2.cpp(946,17): note: while trying to match the argument list '(doctest::assertType::Enum, const char [52], int, const char [23])'

Minimal code example

No response

Error messages

No response

Compiler and operating system

Internal unreleased MSVC

Library version

develop branch of 8f83153

Validation

@dnlbaines
Copy link

Can confirm I am hitting this in Visual Studio 2022 preview, so looks like this will be an issue in the next update.

@nlohmann
Copy link
Owner

Issue #3979 is a duplicate of this. So it's not MSVC specific.

@nlohmann nlohmann added the state: help needed the issue needs help to proceed label Mar 29, 2023
@nlohmann
Copy link
Owner

I still struggle to find a solution here. Help greatly appreciated!

@cardinotGV
Copy link

I had the same issue using the SDK 10.0.22000.0

The workaround was to disable JSON_HAS_THREE_WAY_COMPARISON

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug state: help needed the issue needs help to proceed
Projects
None yet
Development

No branches or pull requests

4 participants