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

VS2015 compile fail #260

Closed
aaron3481 opened this issue Jun 6, 2016 · 9 comments
Closed

VS2015 compile fail #260

aaron3481 opened this issue Jun 6, 2016 · 9 comments
Labels

Comments

@aaron3481
Copy link

Hi all,

I'm trying to import json.hpp into my project. When compiling, an error came out and pointed to line 8500 "max = static_cast<uint64_t>(std::numeric_limits<number_integer_t>::max()) + 1;"

Error Code: C2589 '(': illegal token on right side of '::'

@nlohmann nlohmann added the platform: visual studio related to MSVC label Jun 6, 2016
@nlohmann
Copy link
Owner

nlohmann commented Jun 6, 2016

I'll have a look into this. Just to make sure:

  • Are you using the most recent version from the develop branch?
  • Which version of MSVC are you using?

I'm asking because AppVeyor could execute all tests successfully (https://ci.appveyor.com/project/nlohmann/json) with MSVC 19.0.23918.0.

@Michael-Kelley
Copy link

I can confirm that this does happen with the most recent commit in VS2015. This is due to the fact that Windows defines max() and min() as macros in windows.h. You can avoid the macro expansion by surrounding numeric_limits::max in extra parentheses, like so:
max = static_cast<uint64_t>((std::numeric_limits<number_integer_t>::max)()) + 1;

@gregmarr
Copy link
Contributor

gregmarr commented Jun 6, 2016

You can also add the following to prevent them from being defined, as long as none of your code requires them to be defined, or you can update your code.
#define NOMINMAX

@aaron3481
Copy link
Author

Many thanks to all. I will test right the way

@aaron3481
Copy link
Author

@nlohmann I'm using VS Community 2015 Version 14.0.23107.0 D14REL and it is the most recent version from the develop branch

@aaron3481
Copy link
Author

@Epidal your suggestion fix the issues. Thx
@gregmarr NOMINMAX seems not work

@gregmarr
Copy link
Contributor

gregmarr commented Jun 6, 2016

You need to define that before including any Windows headers.

nlohmann added a commit that referenced this issue Jun 6, 2016
@nlohmann
Copy link
Owner

nlohmann commented Jun 6, 2016

I committed the fix, but I won't merge it before Travis builds it (there seem to be problems with the LLVM's apt server...)

@nlohmann
Copy link
Owner

Finally merged commit b508d1f to develop branch.

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

4 participants