Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 946 Bytes

c26453.md

File metadata and controls

40 lines (30 loc) · 946 Bytes
title description ms.date ms.topic f1_keywords helpviewer_keywords dev_langs
C26453
Describes the causes of MSVC code analysis warning C26453, and shows how to fix it.
07/15/2020
reference
C26453
C26453
C++

Warning C26453

Arithmetic overflow: Left shift of a negative signed number is undefined behavior

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

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 = static_cast<unsigned>(-1) << shiftCount; // OK

  // code
}

See also

ES.102: Use signed types for arithmetic