Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.16 KB

c26453.md

File metadata and controls

47 lines (35 loc) · 1.16 KB
title description ms.date f1_keywords helpviewer_keywords
Warning C26453
Describes the causes of MSVC code analysis warning C26453, and shows how to fix it.
05/11/2023
C26453
LEFTSHIFT_NEGATIVE_SIGNED_NUMBER
C26453

Warning C26453

Arithmetic overflow: Left shift of a negative signed number is undefined behavior (io.4)

Remarks

This warning indicates the code left shifts a negative signed integral value, which is nonportable and triggers implementation defined behavior.

Code analysis name: LEFTSHIFT_NEGATIVE_SIGNED_NUMBER

Example

void leftshift(int shiftCount)
{
  const auto result = -1 << shiftCount;  // C26453 reported here

  // code
}

To correct this warning, use the following code:

void leftshift(int shiftCount)
{
  const auto result = ~0u << shiftCount; // OK

  // code
}

See also

26450
26451
26452
26454
ES.101: Use unsigned types for bit manipulation
ES.102: Use signed types for arithmetic