Why can integer type int64_t not hold this legal value?

You may write

int64_t a = -1 - 9223372036854775807LL;

The problem is that the - is not part of the literal, it is unary minus. So the compiler first sees 9223372036854775808LL (out of range for signed int64_t) and then finds the negative of this.

By applying binary minus, we can use two literals which are each in range.


Ben's already explained the reason, here's two other possible solutions.

Try this

int64_t a = INT64_MIN;

or this

int64_t a = std::numeric_limits<int64_t>::min();