title | description | ms.date | f1_keywords | helpviewer_keywords | |||
---|---|---|---|---|---|---|---|
Warning C26452 |
Describes causes of MSVC Code analysis warning C26452, and how to fix the issue. |
07/15/2020 |
|
|
Arithmetic overflow: Left shift count is negative or greater than or equal to the operand size, which is undefined behavior (io.3)
This warning indicates the shift count is negative, or greater than or equal to the number of bits in the shifted operand. Either case results in undefined behavior.
Warning C4293 is a similar check in the Microsoft C++ compiler.
Code analysis name: SHIFT_COUNT_NEGATIVE_OR_TOO_BIG
unsigned long long combine(unsigned lo, unsigned hi)
{
return (hi << 32) | lo; // C26252 here
}
To correct this warning, use the following code:
unsigned long long combine(unsigned lo, unsigned hi)
{
return (static_cast<unsigned __int64>(hi) << 32) | lo; // OK
}
26450
26451
26453
26454
ES.101: Use unsigned types for bit manipulation
ES.102: Use signed types for arithmetic