Skip to content

Latest commit

 

History

History
50 lines (39 loc) · 1.39 KB

c26450.md

File metadata and controls

50 lines (39 loc) · 1.39 KB
title description ms.date f1_keywords helpviewer_keywords
Warning C26450
Describes the causes of MSVC code analysis warning C26450 and how to fix it.
05/11/2023
C26450
RESULT_OF_ARITHMETIC_OPERATION_PROVABLY_LOSSY
C26450

Warning C26450

Arithmetic overflow: 'operator' operation causes overflow at compile time. Use a wider type to store the operands (io.1)

Remarks

This warning indicates that an arithmetic operation was provably lossy at compile time. It can be asserted when the operands are all compile-time constants. Currently, we check left shift, multiplication, addition, and subtraction operations for such overflows.

Warning C4307 is a similar check in the Microsoft C++ compiler.

Code analysis name: RESULT_OF_ARITHMETIC_OPERATION_PROVABLY_LOSSY

Examples

int multiply()
{
    const int a = INT_MAX;
    const int b = 2;
    int c = a * b; // C26450 reported here
    return c;
}

To correct this warning, use the following code.

long long multiply()
{
    const int a = INT_MAX;
    const int b = 2;
    long long c = static_cast<long long>(a) * b; // OK
    return c;
}

See also

26451
26452
26453
26454
ES.103: Don't overflow