fix warnings in serializer.hpp for VS2019#1969
Conversation
If anything, the expression What MSVC complains about is that computation is done in 32 bits first and then the result is widened to 64bits (a.k.a. std::size_t). Such a warning makes sense in circumstances where people expect the result of a computation might need more than 32 bits and thus assign the result to a 64 bit variable, but forget that the computation itself (and resulting overflow) still happens in 32 bits. But here the result must be less than 400 (the size of the array) anyway and it doesn't matter if computation happens in 32 or 64 bits. At most, an argument can be made that computation has to happen in something bigger than 8 bits, but this is anyway happening as per the language rules no matter the input types (any small integral type gets promoted to int or unsigned int before the actual operation takes place). |
I agree with you. In addition, @nlohmann , what is this project's policy about these annoying compiler warnings? |
|
The "policy" of the library is to be warning-free where possible. However, this is getting more and more difficult, because some warnings are loaded with stylistic opinions, and it gets impossible to write code where all compilers remain silent. In this specific case, it seems only MSVC complains, and though it would be nice to silence the warning, I am hesitant to achieve this "whatever it takes". I put the codep = (state != UTF8_ACCEPT)
? (byte & 0x3fu) | (codep << 6u)
: (0xFFu >> type) & (byte);
state = utf8d[256u + state * 16u + type];into codep = (static_cast<int>(state) != static_cast<int>(UTF8_ACCEPT))
? (static_cast<unsigned int>(byte) & 63U) | (codep << 6U)
: (255U >> static_cast<int>(type)) & static_cast<unsigned int>((byte));
state = utf8d.operator[](static_cast<unsigned long>((256U + (static_cast<unsigned int>(state) * 16U)) + static_cast<unsigned int>(type)));Maybe this can help to find a fix for the issue. |
Right. The newest version of this PR had move it out. |
|
Ready to go. |
|
Thanks! |
🔖 Release itemThis issue/PR will be part of the next release of the library. This template helps preparing the release notes. Type
Description
|
Refer to #1911
fix warnings in serializer.hpp for VS2019