Skip to content

Commit eed7b9c

Browse files
burblebeetkoeppe
authored andcommitted
CWG2753 Storage reuse for string literal objects and backing arrays
1 parent 7b2b2e1 commit eed7b9c

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

source/basic.tex

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3300,6 +3300,12 @@
33003300
standard-layout type\iref{basic.types.general} shall occupy contiguous bytes of
33013301
storage.
33023302

3303+
\pnum
3304+
An object is a \defnadj{potentially non-unique}{object} if it is
3305+
a string literal object\iref{lex.string},
3306+
the backing array of an initializer list\iref{dcl.init.ref}, or
3307+
a subobject thereof.
3308+
33033309
\pnum
33043310
\indextext{most derived object!bit-field}%
33053311
\indextext{most derived object!zero size subobject}%
@@ -3312,7 +3318,9 @@
33123318
if one is nested within the other,
33133319
or
33143320
if at least one is a subobject of zero size
3315-
and they are of different types;
3321+
and they are of different types,
3322+
or
3323+
if they are both potentially non-unique objects;
33163324
otherwise, they have distinct addresses
33173325
and occupy disjoint bytes of storage.
33183326
\begin{footnote}
@@ -3326,6 +3334,14 @@
33263334
static const char test1 = 'x';
33273335
static const char test2 = 'x';
33283336
const bool b = &test1 != &test2; // always \tcode{true}
3337+
3338+
static const char (&r) [] = "x";
3339+
static const char *s = "x";
3340+
static std::initializer_list<char> il = { 'x' };
3341+
const bool b2 = r != il.begin(); // unspecified result
3342+
const bool b3 = r != s; // unspecified result
3343+
const bool b4 = il.begin() != &test1; // always \tcode{true}
3344+
const bool b5 = r != &test1; // always \tcode{true}
33293345
\end{codeblock}
33303346
\end{example}
33313347
The address of a non-bit-field subobject of zero size is

source/declarations.tex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6069,8 +6069,9 @@
60696069
\end{note}
60706070
If a narrowing conversion is required to initialize any of the elements,
60716071
the program is ill-formed.
6072-
Whether all backing arrays are distinct
6073-
(that is, are stored in non-overlapping objects) is unspecified.
6072+
\begin{note}
6073+
Backing arrays are potentially non-unique objects\iref{intro.object}.
6074+
\end{note}
60746075

60756076
\pnum
60766077
The backing array has the same lifetime as any other temporary

source/lex.tex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,11 +1955,12 @@
19551955
\pnum
19561956
Evaluating a \grammarterm{string-literal} results in a string literal object
19571957
with static storage duration\iref{basic.stc}.
1958-
\indextext{string!distinct}%
1959-
Whether all \grammarterm{string-literal}s are distinct (that is, are stored in
1960-
nonoverlapping objects) and whether successive evaluations of a
1958+
\begin{note}
1959+
String literal objects are potentially non-unique\iref{intro.object}.
1960+
Whether successive evaluations of a
19611961
\grammarterm{string-literal} yield the same or a different object is
19621962
unspecified.
1963+
\end{note}
19631964
\begin{note}
19641965
\indextext{literal!string!undefined change to}%
19651966
The effect of attempting to modify a string literal object is undefined.

0 commit comments

Comments
 (0)