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

Warnings with Visual Studio c++ (VS2015 Update 3) #453

Closed
tksatware opened this issue Feb 15, 2017 · 5 comments
Closed

Warnings with Visual Studio c++ (VS2015 Update 3) #453

tksatware opened this issue Feb 15, 2017 · 5 comments

Comments

@tksatware
Copy link

When using the library with uint64_t values, some specialisations throw al lot of warnings (4267 and 4293).
The resulting code works fine, but I like a clean build log :)

So I propose to add the following lines before the first namespace Definition (line 103):

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4267 4293)
#endif

and this at the end before the last #endif:

#if defined(_MSC_VER)
#pragma warning(pop)
#endif

This also could be solved with type casts, but I think they would make the code less readable.

@nlohmann
Copy link
Owner

Interesting - it seems as if MSVC treats number literals like 0x9a as size_t and warns about the conversion to unsigned char. I shall have a look whether there is a way to fix it without the pragmas.

nlohmann added a commit that referenced this issue Feb 17, 2017
@nlohmann nlohmann self-assigned this Feb 17, 2017
@nlohmann nlohmann added this to the Release 2.1.1 milestone Feb 17, 2017
@prsyahmi
Copy link

Adding another cast to all add_to_vector 8-bytes shift solve warning C4293

            case 8:
            {
                vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 070) & 0xff));
                vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 060) & 0xff));
                vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 050) & 0xff));
                vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 040) & 0xff));
                // intentional fall-through
            }

The 8-bytes add_to_vector however is never executed for string,object and array when targeting x86 on msvc since the size_type = size_t = 32bits. This (probably a dirty) fix works for me since I don't use large json data that exceeds 4GB.

@tksatware
Copy link
Author

tksatware commented Feb 19, 2017 via email

nlohmann added a commit that referenced this issue Feb 19, 2017
@nlohmann
Copy link
Owner

Both warnings to not occur any more. I think this can be closed, right?

@tksatware
Copy link
Author

tksatware commented Feb 19, 2017

Confirmed! Thanks! Also on gcc 4.9.2, (raspian 4.9.2-10) where similar warnings occured.

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

No branches or pull requests

3 participants