The reason is that the compiler int a = 2147483647 + 10; can predict the result of operator ( a ), and he will know that it causes an overflow, since 2147483647 and 10 > are constants, and their values โโare known at compile time.
But when you
int ten = 10; int b = 2147483647 + ten;
Some other threads (or something else, perhaps a master, perhaps a danger in memory ...) may have changed the value of ten before executing the operator int b = 2147483647 + ten; , and overflow cannot be predicted at compile time.
source share