|Project:||Programming Language C++|
|Reply to:||Alisdair Meredith <firstname.lastname@example.org>|
Original version of the paper for the 2015 pre-Kona mailing.
Revisions following core wording review:
The ++ operator for bool was deprecated in the original 1998 C++ standard, and it is past time to formally remove it.
During the development of C++14, the Core working group chair suggested that it was time to remove this deprecated operator from the standard, and the author of this paper expressed a concern that the post-increment operator still had rare but valid uses.
In response to that concern, the function std::exchange was added to the C++14 standard library, but the paper to finally remove the deprecated operator did not follow. The intent of this paper is to finally complete the process started during the evolution of C++14.
When the (planned) C++17 standard is published, users will have had 20 years to prepare for this removal, significantly longer than has been allowed for previously removed deprecated features. See the references at the end of this paper for a list of other deprecated features expected to be removed from the next version of the standard.
The impact on the standard is minimal, as there is no known dependency in the library on this feature, and we must already accomodate the fact that the -- operator has never been supported for bool.
It was noted that this might affect compatiblity with C when the <stdbool.h> header is included, but there is already a compability concern that operator-- was never supported for bool so we defer any discussion of updating the C compatiblity Annex to a pending Core issue that will be opened for this topic.
The wording follows, as closely as possible, the style of wording that is used to exempt bool from supporting the -- operator.
Consideration was given to whether it would make sense to remove bool from the set of arithmetic types, given it no longer supports the full set of arithmetic operations. That seems to be a much larger issue in scope, and the proposed change seems no worse than the existing situation where the -- operator is not supported. The small number of edits needed to effect this removal, compared to a much larger set of ammendents to rules that would need to be added if we decided that bool was no longer arithmetic, suggest that we are not yet in a position where we should consider that question.
Although cv qualified bool types are also arithmetic types, that distinction is ignored, in keeping with the wording that is being replaced. An alternate phrasing of "non-bool arithmetic type" was also considered, with no clear preferance by the author, deferring final choice to the Core wording review.
Make the following edits:
2 [ Note: Operators can be overloaded, that is, given meaning when
applied to expressions of class type (Clause 9) or enumeration type (7.2). Uses
of overloaded operators are transformed into function calls as described in
13.5. Overloaded operators obey the rules for syntax specified in Clause 5,
but the requirements of operand type, value category, and evaluation order are
replaced by the rules for function call. Relations between operators, such as
++a meaning a+=1, are not guaranteed for overloaded operators
, and are not guaranteed for operands of type bool.
- end note ]
1 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 value computation of the ++ expression is sequenced before the modification of the operand object.
With respect to an indeterminately-sequenced function call, the operation of postfix ++ is a single evaluation.
[Note: Therefore, a function call shall not intervene between the lvalue-to-rvalue conversion and the side effect associated with any single postfix ++ operator. —end note]
The result is a prvalue. The type of the result is the cv-unqualified version of the type of the operand. If the operand is a bit-field that cannot represent the incremented value, the resulting value of the bit-field is implementation-defined. See also 5.7 and 5.18.
2 The operand of postfix -- is decremented analogously to the postfix ++ operator
, except that the operand shall not be of type bool.
[Note: For prefix increment and decrement, see 5.3.2. — end note]
1 The operand of prefix ++ is modified by adding 1
, or set to true if it is bool (this use is deprecated).
The operand shall be a modifiable lvalue. The type of the operand shall be an arithmetic type
or a pointer to a completely-defined object type.
2 The operand of prefix -- is modified by subtracting 1.
The operand shall not be of type bool.
The requirements on the operand of prefix -- and the properties of its result are otherwise the same as those of
prefix ++. [ Note: For postfix increment and decrement, see 5.2.6. — end note ]
3 For every pair (T, VQ), where T is an arithmetic type, and VQ is either volatile or empty, there exist candidate operator functions of the form
VQ T& operator++(VQ T&); T operator++(VQ T&, int);
1 The use of an operand of type bool with the ++ operator is deprecated (see 5.3.2 and 5.2.6).
Bjarne Stroustrup filed the original issue against the C++14 CD, and Jeffrey Yasskin provided the std::exchange library function that can serve as a substitute in existing code relying on the deprecated feature.