This is how the ++
operator is specified. See C++11 §5.2.6[expr.post.incr]/1 (emphasis mine):
The value of a postfix
++
expression is the value of its operand. [Note: the value obtained is a copy of the original value —end note] The operand shall be a modifiable lvalue. The type of the operand shall be an arithmetic type or a pointer to a complete object type.The value of the operand object is modified by adding 1 to it, unless the object is of type bool, in which case it is set to true. [Note: this use is deprecated, see Annex D. —end note]
(The prefix ++
operator has similar language to allow it to be applied to a bool
value.)
Modifying the bool
object through a pointer or reference of a type other than bool
yields undefined behavior.