-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Full name of submitter: Lénárd Szolnoki
Reference (section label): [expr.post.incr]
The value of the operand object is modified by adding
1
to it.
Issue description
consider:
int8_t x = 127;
x++;
This has undefined behavior: the value is increased by 1 but the resulting value is not representable in int8_t [expr.pre].
In comparison [expr.pre.incr] in addition has:
The expression
++x
is equivalent tox+=1
.
Which in turn is equivalent to x = x + 1
, except that x
is evaluated only once. This implies that integral promotion rules are considered.
Because of this the following is defined:
int8_t x = 127;
++x;
where ++x
is equivalent to x = (int)x + 1
.
Implementations
GCC, clang and MSVC accept both examples above in constant expressions. They otherwise detect overflowing increments when no promotion is involved.
Suggested resolution
Spell out that the side effects of post-increment are equivalent to the side-effects of pre-increment, with the implied integral promotions.