Skip to content

Commit 9dadc2c

Browse files
committed
Enhance rationale for 4378 P/R and use American spelling
1 parent 4979bd3 commit 9dadc2c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

xml/issue4378.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,15 @@ instead of repeating it in `operator[]` and `c_str()`.
119119
</p>
120120
<p>
121121
We can also permit modifying the string contents through
122-
<code>const_cast&lt;charT*&gt;(str.c_str())</code>,
123-
since there's no reason for that to be undefined when
124-
<code>const_cast&lt;string&amp;&gt;(str).data()</code> is allowed.
122+
<code>const_cast&lt;char*&gt;(str.c_str())[0]</code>.
123+
There's no reason for that to be undefined when
124+
<code>const_cast&lt;string&amp;&gt;(str)[0]</code> and
125+
<code>const_cast&lt;string&amp;&gt;(str).data()[0]</code>
126+
are both allowed.
127+
The only restriction should be on changing the null terminator.
128+
Changing any other characters through `c_str() const` or `data() const`
129+
is no different to changing them through the non-const `data()`,
130+
and does not need to cause undefined behaviour.
125131
</p>
126132

127133
</discussion>
@@ -139,7 +145,7 @@ In all cases, [`data()`, `data() + size()`] is a valid range,
139145
(a "null terminator"), and <tt>size() &lt;= capacity()</tt> is `true`.
140146
<ins>
141147
Non-const access to the null terminator is possible,
142-
e.g. using `*(data()+size())`, but the program has undefined behaviour
148+
e.g. using `*(data()+size())`, but the program has undefined behavior
143149
if the null terminator is modified to any value other than `charT()`.
144150
</ins>
145151
</p>

0 commit comments

Comments
 (0)