[libcxx-bugs] Incoherent behaviour on integer overflow

+libcxx-dev as I'm not sure how many people read libcxx-bugs.

Trying again, with the original attachments.

error_output.txt (5.26 KB)

overflow_erro.cpp (1.54 KB)

The behavior is correct. There are 2 different kinds of errors here:

1a. For int8_t, int16_t, uint8_t and uint16_t: when computing e.g.
std::numeric_limits<std::int8_t>::min()-1, the left hand side is promoted to int
according to the standard promotion rules, then the computation is performed,
the result is an integral constant -129 of type int not fitting in int8_t. This
causes the instantiation of std::integral_constant<std::int8_t, ...> to fail.

1b. Same applies to std::integral_constant<std::uint32_t, -1>

2. For int32_t and int64_t: evaluating e.g.
(std::numeric_limits<std::int32_t>::min() - 1) causes signed integer overflow,
i.e., undefined behavior. Since the expression is evaluated as a constant
expression, the UB is diagnosed by the compiler.

For uint32_t and uint64_t neither promotion, nor signed overflow applies. The
result is wrapped, e.g. (std::numeric_limits<std::uint32_t>::max() + 1) is
constant 0 of type uint32_t.