-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Use the U literal for unsigned integer constants. #3549
Conversation
Fix MSVC Error C2398 Element '1': conversion from 'int' to 'const uint32_t' requires a narrowing conversion.
What compiler options do you use? Or, better, do you have a godbolt repro? |
Uh, that's interesting! Actually, it seems to be the NVIDIA CUDA and not the MSVC compiler, I'm using in my private project to build some .cu files too, where I'm including the
Line 1808 in Unfortunately this warning transforms to an error... |
I'm not sure, if this issue can be reproduced via godbolt: https://godbolt.org/z/WW44ezoWG It might be a combination of NVCC and MSVC on Windows... This is the version of the NVCC I'm using in my project, if this is of any help:
Otherwise I'm introducing no special compiler options and keeping CMake defaults as is. |
Finally a minimal example to reproduce at least the particular warning integer conversion resulted in a change of sign in Windows environment: CMakeLists.txt
main.cu #include <cstdint>
// For checking rounding thresholds.
// The kth entry is chosen to be the smallest integer such that the
// upper 32-bits of 10^(k+1) times it is strictly bigger than 5 * 10^k.
static constexpr uint32_t fractional_part_rounding_thresholds[8] = {
2576980378, // ceil(2^31 + 2^32/10^1)
2190433321, // ceil(2^31 + 2^32/10^2)
2151778616, // ceil(2^31 + 2^32/10^3)
2147913145, // ceil(2^31 + 2^32/10^4)
2147526598, // ceil(2^31 + 2^32/10^5)
2147487943, // ceil(2^31 + 2^32/10^6)
2147484078, // ceil(2^31 + 2^32/10^7)
2147483691 // ceil(2^31 + 2^32/10^8)
};
int main()
{
return fractional_part_rounding_thresholds[0];
} Build log
Appending the U literal will fix this, which is the purpose of this PR. |
I recommend reporting to NVIDIA since this is clearly a bug in their compiler. |
Anyway, this is simple enough change to go in but please do report this false positive to your compiler vendor. |
Thanks! I also have submitted a bug report to developer.nvidia.com. |
Under certain circumstances, MSVC (Visual Studio 2022) produces the following compile time error:
Appending the U literal in
fractional_part_rounding_thresholds
solves this problem.