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

Implicit cast to std::string broken again with VS2019 16.5.0 #2006

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

Implicit cast to std::string broken again with VS2019 16.5.0 #2006

garethsb opened this issue Mar 24, 2020 · 4 comments
Assignees
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@garethsb
Copy link
Contributor

  • What is the issue you have?
  • What is the expected behavior?
  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

The following program should compile.

#include "nlohmann/json.hpp"

void foo()
{
    std::string s;
    nlohmann::json j;
    s = j;
}
  • And what is the actual behavior instead?
  • Which compiler and operating system are you using? Is it a supported compiler?

With Visual Studio 2019 version 16.5.0, the above fails to compile. This is a recent release, but comes under "Microsoft Visual C++ 2019 / Build Tools 16.3.1+1def00d3d (and possibly later)".

The error message is:

foo.cpp(7,10): error C2593: 'operator =' is ambiguous
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.25.28610\include\xstring(2591,19): message : could be 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator =(std::initializer_list<_Elem>)'
1>        with
1>        [
1>            _Elem=char
1>        ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.25.28610\include\xstring(2492,19): message : or       'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator =(std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&) noexcept(<expr>)'
1>foo.cpp(7,10): message : while trying to match the argument list '(std::string, nlohmann::json)'
  • Did you use a released version of the library or the version from the develop branch?

I tried both a recent release and HEAD of develop.

The same error message is reported when trying to compile test\src\unit-conversions.cpp.

In both cases the error can be resolved by removing the #ifndef _MSC_VER which ends up at https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp#L17468 (and the corresponding #endif!). FWIW, in my testing with VS 2015 (for which that preprocessor condition was added), the code also compiles fine when it is removed.

The compile-time and preprocessor conditions to enable implicit conversions have obviously been revisited many times over the life of nlohmann/json. A good place to start looking at the history is #188.

@t-b
Copy link
Contributor

t-b commented Mar 24, 2020

Unfortunately appveyor 1 is still at 16.4.
But nevertheless can you provide a PR based on your findings? It might be easiest to first try dropping the #ifndef altogether.

garethsb added a commit to garethsb/json that referenced this issue Mar 24, 2020
@emmenlau
Copy link

emmenlau commented Apr 2, 2020

Thanks @garethsb-sony !

nlohmann added a commit that referenced this issue Apr 5, 2020
@nlohmann
Copy link
Owner

nlohmann commented Apr 5, 2020

With #2008 merged, can this issue be closed?

@emmenlau
Copy link

emmenlau commented Apr 6, 2020

From my side, yes, my issue is fixed.

@nlohmann nlohmann added release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Apr 6, 2020
@nlohmann nlohmann self-assigned this Apr 6, 2020
@nlohmann nlohmann added this to the Release 3.7.4 milestone Apr 6, 2020
@nlohmann nlohmann closed this as completed Apr 6, 2020
vslavik added a commit to vslavik/poedit that referenced this issue May 10, 2020
Visual Studio 16.5 broke JSON for Modern C++'s implicit cast to
std::string.

Update bundled copy to current snapshot to fix.

See nlohmann/json#2006
berezins pushed a commit to berezins/poedit that referenced this issue Jun 9, 2020
Serhiy:
- This is temporary cherry-pick from master to tetatetit:crowdin-new-oauth-api-xliff-clean PR
- To be removed before final merge PR to master (to avoid conflict/duplication)
- Necessary in order to remove some workaounds on JSON in this PR (which become needless with this commit) while to keep this PR buildable on Visual Studio

Visual Studio 16.5 broke JSON for Modern C++'s implicit cast to
std::string.

Update bundled copy to current snapshot to fix.

See nlohmann/json#2006
berezins pushed a commit to berezins/poedit that referenced this issue Jun 9, 2020
Serhiy:
- This is temporary cherry-pick from master to tetatetit:crowdin-new-oauth-api-xliff-clean PR
- To be removed before final merge PR to master (to avoid conflict/duplication)
- Necessary in order to remove some workaounds on JSON in this PR (which become needless with this commit) while to keep this PR buildable on Visual Studio

Visual Studio 16.5 broke JSON for Modern C++'s implicit cast to
std::string.

Update bundled copy to current snapshot to fix.

See nlohmann/json#2006
berezins pushed a commit to berezins/poedit that referenced this issue Jun 9, 2020
Serhiy:
- This is temporary cherry-pick from master to tetatetit:crowdin-new-oauth-api-xliff-clean PR
- To be removed before final merge PR to master (to avoid conflict/duplication)
- Necessary in order to remove some workaounds on JSON in this PR (which become needless with this commit) while to keep this PR buildable on Visual Studio

Visual Studio 16.5 broke JSON for Modern C++'s implicit cast to
std::string.

Update bundled copy to current snapshot to fix.

See nlohmann/json#2006
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

4 participants