<html>

<head>
<title>Remove Deprecated operator++(bool)</title>
<style type="text/css">
  p {text-align:justify}
  li {text-align:justify}
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
</style>
</head>

<body>
<table>
<tr>
  <td align="left">Doc. no.</td>
  <td align="left">P0002R1</td>
</tr>
<tr>
  <td align="left">Date:</td>
  <td align="left">2015-10-23</td>
</tr>
<tr>
  <td align="left">Project:</td>
  <td align="left">Programming Language C++</td>
</tr>
<tr>
  <td align="left">Reply to:</td>
  <td align="left">Alisdair Meredith &lt;<a href="mailto:ameredith1@bloomberg.net">ameredith1@bloomberg.net</a>&gt;</td>
</tr>
</table>

<h2><a name="0.0">Revision History</a></h2>

<h3><a name="0.1">Revision 0</a></h3>
<p>
Original version of the paper for the 2015 pre-Kona mailing.
</p>

<h3><a name="0.2">Revision 1</a></h3>
<p>
Revisions following core wording review:
</p>
<ul>
  <li>operator++ should is not available for <i>cv</i> qualified <tt>bool</tt></li>
  <li>C++14 compatibility clause should refer to an lvalue, not an xvalue.</li>
  <li>Editorial nits</li>
</ul>


<h1>Remove Deprecated <tt>operator++(bool)</tt></h1>

<h2>I. Table of Contents</h2>

<h2><a name="1.0">I. Table of Contents</a></h2>
<ul>
<li><a href="#0.0">Revision History</a></li>
<ul>
  <li><a href="#0.1">Revision 0</a></li>
  <li><a href="#0.2">Revision 1</a></li>
</ul>
<li><a href="#2.0">II. Introduction</a></li>
<li><a href="#3.0">III. Motivation and Scope</a></li>
<li><a href="#4.0">IV. Impact On the Standard</a></li>
<li><a href="#5.0">V. Design Decisions</a></li>
<li><a href="#6.0">VI. Technical Specification</a></li>
<ul>
  <li><a href="#6.00">5 Expressions [expr]</a></li>
  <li><a href="#6.1">5.2.6 Increment and decrement [expr.post.incr]</a></li>
  <li><a href="#6.2">5.3.2 Increment and decrement [expr.pre.incr]</a></li>
  <li><a href="#6.3">13.6 Built-in operators [over.built]</a></li>
  <li><a href="#6.4">C.4.2 Annex D: compatibility features [diff.cpp14.depr]</a></li>
  <li><a href="#6.5">D.1 Increment operator with <tt>bool</tt> operand [depr.incr.bool]</a></li>
</ul>
<li><a href="#7.0">VII. Acknowledgements</a></li>
<li><a href="#8.0">VIII. References</a></li>
</ul>


<h2><a name="2.0">II. Introduction</a></h2>

<p>
The <tt>++</tt> operator for <tt>bool</tt> was deprecated in the original 1998 C++ standard,
and it is past time to formally remove it.
</p>


<h2><a name="3.0">III. Motivation and Scope</a></h2>

<p>
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.
</p>
<p>
In response to that concern, the function <tt>std::exchange</tt> 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.
</p>
<p>
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.
</p>


<h2><a name="4.0">IV. Impact On the Standard</a></h2>

<p>
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 <tt>--</tt> operator has never been
supported for <tt>bool</tt>.
</p>

<p>
It was noted that this might affect compatiblity with C when the <tt>&lt;stdbool.h&gt;</tt> header
is included, but there is already a compability concern that <tt>operator--</tt> was never
supported for <tt>bool</tt> so we defer any discussion of updating the C compatiblity Annex to
a pending Core issue that will be opened for this topic.
</p>

<h2><a name="5.0">V. Design Decisions</a></h2>

<p>
The wording follows, as closely as possible, the style of wording that is used to exempt
<tt>bool</tt> from supporting the <tt>--</tt> operator.
</p>
<p>
Consideration was given to whether it would make sense to remove <tt>bool</tt> 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 <tt>--</tt> 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 <tt>bool</tt> was no longer arithmetic, suggest
that we are not yet in a position where we should consider that question.
</p>

<p>
Although <i>cv</i> qualified <tt>bool</tt> types are also arithmetic types, that distinction is
ignored, in keeping with the wording that is being replaced.  An alternate phrasing of
&quot;non-<tt>bool</tt> arithmetic type&quot; was also considered, with no clear preferance by
the author, deferring final choice to the Core wording review.
</p>


<h2><a name="6.0">VI. Technical Specifications</a></h2>

<p>
Make the following edits:
</p>

<h3><a name="6.00">5 Expressions [expr]</a></h3>
<p>
2 [ <i>Note</i>: 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
<tt>++a</tt> meaning <tt>a+=1</tt>, are not guaranteed for overloaded operators
(13.5)<del>, and are not guaranteed for operands of type <tt>bool</tt></del>.
<i>- end note</i> ]
</p>

<h3><a name="6.1">5.2.6 Increment and decrement [expr.post.incr]</a></h3>
<p>
1 The value of a postfix <tt>++</tt> expression is the value of its operand.
 [<i>Note:</i> the value obtained is a copy of the original value <i>—end note</i>]
 The operand shall be a modifiable lvalue.
 The type of the operand shall be an arithmetic type <ins>other than <i>cv</i> <tt>bool</tt>,</ins>
 or a pointer to a complete object type. The value of the operand object is modified by adding 1 to it<ins>.</ins>
 <del>, unless the object is of type <tt>bool</tt>, in which case it is set to <tt>true</tt>.
 [<i>Note:</i> this use is deprecated, see Annex D. <i>—end note</i>]</del>
 The value computation of the <tt>++</tt> expression is sequenced before the modification of the operand object.
 With respect to an indeterminately-sequenced function call, the operation of postfix <tt>++</tt> is a single evaluation.
 [<i>Note:</i> Therefore, a function call shall not intervene between the lvalue-to-rvalue conversion and the side effect associated with any single postfix <tt>++</tt> operator. <i>—end note</i>]
 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.
</p>
<p>
2 The operand of postfix <tt>--</tt> is decremented analogously to the postfix ++ operator<del>, except that the operand shall not be of type bool</del>.
  [<i>Note:</i> For prefix increment and decrement, see 5.3.2. <i>— end note</i>]
</p>

<h3><a name="6.2">5.3.2 Increment and decrement [expr.pre.incr]</a></h3>
<p>
1 The operand of prefix <tt>++</tt> is modified by adding 1<del>, or set to true if it is bool (this use is deprecated)</del>.
  The operand shall be a modifiable lvalue. The type of the operand shall be an arithmetic type
  <ins>other than <i>cv</i> <tt>bool</tt>,</ins> or a pointer to a completely-defined object type.
</p>
<p>
2 The operand of prefix <tt>--</tt> is modified by subtracting 1. <del>The operand shall not be of type <tt>bool</tt>.</del>
  The requirements on the operand of prefix <tt>--</tt> and the properties of its result are otherwise the same as those of
  prefix <tt>++</tt>. [ <i>Note:</i> For postfix increment and decrement, see 5.2.6. <i>— end note</i> ]
</p>

<h3><a name="6.3">13.6 Built-in operators [over.built]</a></h3>
<p>
3 For every pair <i>(T, VQ)</i>, where <i>T</i> is an arithmetic type<ins> other than <tt>bool</tt></ins>,
  and <i>VQ</i> is either <tt>volatile</tt> or empty, there exist candidate operator functions of the form
</p>
<pre><tt>
    <i>VQ T</i>&amp; operator++(<i>VQ T</i>&amp;);
    <i>T</i> operator++(<i>VQ T</i>&amp;, int);
</tt></pre>

<h3><ins><a name="6.4">C.4.2 Annex D: compatibility features [diff.cpp14.depr]</a></ins></h3>
<p><ins>D.1</ins></p>
<p><ins><b>Change:</b> Remove increment operator with <tt>bool</tt> operand [depr.incr.bool].</ins></p>
<p><ins><b>Rationale:</b> Obsolete feature with occasionally surprising semantics.</ins></p>
<p><ins><b>Effect on original feature:</b> A valid C++ 2014 expression utilizing the increment operator
on a <tt>bool</tt> lvalue is ill-formed in this International Standard.  Note that this might occur
when the lvalue has a type given by a template parameter.</ins></p>

<h3><a name="6.5"><del>
D.1 Increment operator with <tt>bool</tt> operand [depr.incr.bool]</b></del></a></h3>
<p><del>
1 The use of an operand of type <tt>bool</tt> with the <tt>++</tt> operator is deprecated (see 5.3.2 and 5.2.6).
</del></p>


<h2><a name="7.0">VII. Acknowledgements</a></h2>
<p>
Bjarne Stroustrup filed the original issue against the C++14 CD, and Jeffrey Yasskin provided the <tt>std::exchange</tt>
library function that can serve as a substitute in existing code relying on the deprecated feature.
</p>


<h2><a name="8.0">VIII. References</a></h2>
<ul>
  <li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3668">N3668</a> exchange() utility function, revision 3, Jeffrey Yasskin</li>
  <li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4086">N4086</a> Removing trigraphs??!, Richard Smith</li>
  <li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4168">N4168</a> Removing <tt>auto_ptr</tt>, Billy Baker</li>
  <li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4190">N4190</a> Removing <tt>auto_ptr</tt>, <tt>random_shuffle()</tt>, And Old <tt>&lt;functional&gt;</tt> Stuff, Stephan T. Lavavej</li>
  <li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4193.html#809">Core issue 809</a> Deprecation of the <tt>register</tt> keyword</li>
  <li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4192.html#1653">Core issue 1653</a> Removing deprecated increment of <tt>bool</tt></li>
</ul>

</body>

</html>
