description | title | keywords | ms.date | ms.topic | f1_keywords | helpviewer_keywords | dev_langs | |||
---|---|---|---|---|---|---|---|---|---|---|
Learn more about: Arithmetic overflow: '%operator%' operation causes overflow at compile time. Use a wider type to store the operands |
C26450 |
C26450 |
01/08/2017 |
reference |
|
|
|
Arithmetic overflow: '%operator%' operation causes overflow at compile time. Use a wider type to store the operands
This warning indicates that an arithmetic operation was provably lossy at compile time. This can be asserted when the operands are all compile-time constants. Currently, we check left shift, multiplication, addition, and subtraction operations for such overflows.
Note: C4307 is a similar check in the Microsoft C++ compiler.
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 = (long long)a * b; // OK
return c;
}
int add()
{
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 add()
{
const int a = INT_MAX;
const int b = 2;
long long c = (long long)a + b; // OK
return c;
}
int subtract()
{
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 subtract()
{
const int a = -INT_MAX;
const int b = 2;
long long c = (long long)a - b; // OK
return c;
}