Json: VS2017 min / max problem for 2.1.1

Created on 14 Mar 2017  路  9Comments  路  Source: nlohmann/json

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

visual studio

Most helpful comment

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.

All 9 comments

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

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_json::to_cbor_internal(const nlohmann::basic_json &,std::vector> &)'
with
[
_Ty=uint8_t
]
json.hpp(8008): note: see reference to function template instantiation 'void nlohmann::basic_json::to_cbor_internal(const nlohmann::basic_json &,std::vector> &)' 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_json' 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_json &&>' being compiled
with
[
_Ty=nlohmann::json
]
json.hpp(12932): note: see reference to class template instantiation 'std::is_nothrow_move_constructible' 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

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.

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)

thanks let me check

works perfectly!

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.

ok thanks

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qis picture qis  路  4Comments

CraigHutchinson picture CraigHutchinson  路  4Comments

jmlemetayer picture jmlemetayer  路  3Comments

afowles picture afowles  路  3Comments

Fonger picture Fonger  路  4Comments