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

VS2017 min / max problem for 2.1.1 #506

Closed
meox opened this issue Mar 14, 2017 · 9 comments
Closed

VS2017 min / max problem for 2.1.1 #506

meox opened this issue Mar 14, 2017 · 9 comments
Assignees
Labels
Milestone

Comments

@meox
Copy link

meox commented Mar 14, 2017

In order to avoid some problem with VS2017 I've put this line in my json.hpp 2.1.1

#ifdef WIN32
#define NOMINMAX
#undef min
#undef max
#endif
just after #define NLOHMANN_JOSN_HPP

I don't know how to fix it properly

@nlohmann nlohmann added the platform: visual studio related to MSVC label Mar 14, 2017
@nlohmann
Copy link
Owner

Thanks for reporting. Could you please post the error message that occurs when you don't add the fix?

@meox
Copy link
Author

meox commented Mar 14, 2017

many of them:
json.hpp(6702): warning C4003: not enough actual parameters for macro 'max'
json.hpp(6716): warning C4003: not enough actual parameters for macro 'min'


json.hpp(6926): error C2589: '(': illegal token on right side of '::'
json.hpp(6900): note: while compiling class template member function 'void nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer::to_cbor_internal(const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &,std::vector<uint8_t,std::allocator<_Ty>> &)'
with
[
_Ty=uint8_t
]
json.hpp(8008): note: see reference to function template instantiation 'void nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer::to_cbor_internal(const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &,std::vector<uint8_t,std::allocator<_Ty>> &)' being compiled
with
[
_Ty=uint8_t
]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\type_traits(707): note: see reference to class template instantiation 'nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer' being compiled
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\type_traits(736): note: see reference to class template instantiation 'std::is_nothrow_constructible<_Ty,nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &&>' being compiled
with
[
_Ty=nlohmann::json
]
json.hpp(12932): note: see reference to class template instantiation 'std::is_nothrow_move_constructiblenlohmann::json' being compiled
json.hpp(6926): error C2062: type 'unknown-type' unexpected
json.hpp(6926): error C2059: syntax error: ')'
json.hpp(6927): error C2143: syntax error: missing ';' before '{'
json.hpp(6932): error C2181: illegal else without matching if
json.hpp(6932): error C2589: '(': illegal token on right side of '::'
json.hpp(6932): error C2062: type 'unknown-type' unexpected
json.hpp(6932): error C2059: syntax error: ')'
json.hpp(6933): error C2143: syntax error: missing ';' before '{'
json.hpp(6938): error C2181: illegal else without matching if
json.hpp(6938): error C2589: '(': illegal token on right side of '::'
json.hpp(6938): error C2062: type 'unknown-type' unexpected
json.hpp(6938): error C2059: syntax error: ')'
json.hpp(6939): error C2143: syntax error: missing ';' before '{'
json.hpp(6944): error C2181: illegal else without matching if
json.hpp(6960): error C2589: '(': illegal token on right side of '::'
json.hpp(6960): error C2062: type 'unknown-type' unexpected
json.hpp(6960): error C2059: syntax error: ')'
json.hpp(6961): error C2143: syntax error: missing ';' before '{'
json.hpp(6966): error C2181: illegal else without matching if
json.hpp(6966): error C2589: '(': illegal token on right side of '::'
json.hpp(6966): error C2062: type 'unknown-type' unexpected
json.hpp(6966): error C2059: syntax error: ')'
json.hpp(6967): error C2143: syntax error: missing ';' before '{'
json.hpp(6972): error C2181: illegal else without matching if
json.hpp(6972): error C2589: '(': illegal token on right side of '::'
json.hpp(6972): error C2062: type 'unknown-type' unexpected
json.hpp(6972): error C2059: syntax error: ')'
json.hpp(6973): error C2143: syntax error: missing ';' before '{'
json.hpp(6978): error C2181: illegal else without matching if

@nlohmann
Copy link
Owner

From what I learned about here, this is not a bug in the library, but in headers like <Windows.h> or WinDef.h. It seems that one of this headers where included prior to json.hpp. A better way is described here:

#define NOMINMAX
#include <windows.h>
#undef NOMINMAX

The library is not even using std::max, but std::numeric_limits<T>::max.

@nlohmann
Copy link
Owner

From here, I learned that I could add parentheses around the calls. Could you please try
this file?

(Please note that this is the current develop version which is in an unreleased state)

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Mar 14, 2017
@meox
Copy link
Author

meox commented Mar 14, 2017

thanks let me check

@meox
Copy link
Author

meox commented Mar 14, 2017

works perfectly!

@nlohmann
Copy link
Owner

Great. I shall merge the fix to develop. Please note that this branch is experimental and may change until version 3.0.0 is released.

@nlohmann nlohmann self-assigned this Mar 14, 2017
@nlohmann nlohmann added this to the Release 3.0.0 milestone Mar 14, 2017
@meox
Copy link
Author

meox commented Mar 14, 2017

ok thanks

nlohmann added a commit that referenced this issue Mar 14, 2017
When <Windows.h> is included with MSVC, a macro NOMINMAX is defined
that yields compilation errors when max/min calls are encountered. This
can be fixed by un-defining NOMINMAX, or by placing parentheses around
all min/max calls. We chose the latter.
@nlohmann nlohmann removed the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Mar 14, 2017
@wongdu
Copy link

wongdu commented Dec 30, 2020

From what I learned about here, this is not a bug in the library, but in headers like <Windows.h> or WinDef.h. It seems that one of this headers where included prior to json.hpp. A better way is described here:

#define NOMINMAX
#include <windows.h>
#undef NOMINMAX

The library is not even using std::max, but std::numeric_limits<T>::max.

it's helpful,thanks a lot

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

3 participants