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 fails to compile std::swap specialization for nlohmann::json #1168

Closed
NotAPenguin0 opened this issue Jul 19, 2018 · 1 comment
Closed
Assignees
Labels
Milestone

Comments

@NotAPenguin0
Copy link

  • What is the issue you have?
    When compiling a project using the library, MSVC throws an error:
    no instance of overloaded std::swap matches the specified type.

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
    Any program using the library and compiling with MSVC.

  • What is the expected behavior?
    It should compile (as clang and gcc accept it), even though it is nonstandard.

  • And what is the actual behavior instead?
    It fails to compile

  • Which compiler and operating system are you using? Is it a supported compiler?
    MSVC 15.6 with C++17 enabled on Windows 10

  • Did you use a released version of the library or the version from the develop branch?
    develop

Suggested fix: It should be a specialization, not an overload. This way it compiles on MSVC, and still compiles with clang and gcc:

namespace std
{
    template<>
    inline void swap<nlohmann::json>(nlohmann::json& first, nlohmann::json& second) noexcept(
		is_nothrow_move_constructible<nlohmann::json>::value &&
		is_nothrow_move_assignable<nlohmann::json>::value
		)
        
    {
        first.swap(second);   
    }

}
@nlohmann nlohmann added the platform: visual studio related to MSVC label Jul 19, 2018
nlohmann added a commit that referenced this issue Jul 19, 2018
@nlohmann nlohmann self-assigned this Jul 21, 2018
@nlohmann nlohmann added this to the Release 3.1.3 milestone Jul 21, 2018
@nlohmann
Copy link
Owner

Fixed. Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants