Skip to content

Commit c2de361

Browse files
[ub] Add many missing entries to UB annex (cplusplus#7864)
Co-authored-by: jberne4 <jberne4@bloomberg.net>
1 parent aee26fc commit c2de361

5 files changed

Lines changed: 400 additions & 32 deletions

File tree

source/basic.tex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3840,7 +3840,7 @@
38403840
using the \grammarterm{alignment-specifier}\iref{dcl.align}.
38413841
Attempting to create an object\iref{intro.object} in storage that
38423842
does not meet the alignment requirements of the object's type
3843-
is undefined behavior.
3843+
is undefined behavior.\ubdef{basic.align.object.alignment}
38443844

38453845
\pnum
38463846
A \defnadj{fundamental}{alignment} is represented by an alignment
@@ -4257,7 +4257,7 @@
42574257
then the value produced by that operator is erroneous.
42584258
Except in the following cases,
42594259
if an indeterminate value is produced by an evaluation,
4260-
the behavior is undefined, and
4260+
the behavior is undefined\ubdef{basic.indet.value}, and
42614261
if an erroneous value is produced by an evaluation,
42624262
the behavior is erroneous and
42634263
the result of the evaluation is that erroneous value:
@@ -4584,7 +4584,7 @@
45844584
\tcode{p0} represents the address of a block of storage disjoint from the storage
45854585
for any other object accessible to the caller.
45864586
The effect of indirecting through a pointer
4587-
returned from a request for zero size is undefined.
4587+
returned from a request for zero size is undefined.\ubdef{basic.stc.alloc.zero.dereference}
45884588
\begin{footnote}
45894589
The intent is
45904590
to have \tcode{\keyword{operator} \keyword{new}()} implementable by
@@ -4707,7 +4707,7 @@
47074707
signature.
47084708

47094709
\pnum
4710-
If a deallocation function terminates by throwing an exception, the behavior is undefined.
4710+
If a deallocation function terminates by throwing an exception, the behavior is undefined.\ubdef{basic.stc.alloc.dealloc.throw}
47114711
The value of the first argument supplied to a deallocation function may
47124712
be a null pointer value; if so, and if the deallocation function is one
47134713
supplied in the standard library, the call has no effect.
@@ -6087,7 +6087,7 @@
60876087
$P$ is not valid in the context of $E$,
60886088
then the behavior is undefined if $E$ is
60896089
an indirection\iref{expr.unary.op} or
6090-
an invocation of a deallocation function\iref{basic.stc.dynamic.deallocation},
6090+
an invocation of a deallocation function\iref{basic.stc.dynamic.deallocation}\ubdef{basic.compound.invalid.pointer},
60916091
and \impldef{invalid pointer value in the context of an evaluation} otherwise.
60926092
\begin{footnote}
60936093
Some implementations might define that

source/classes.tex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6037,9 +6037,10 @@
60376037
\indextext{destruction!member access}%
60386038
For an object with a non-trivial constructor, referring to any non-static member
60396039
or base class of the object before the constructor begins execution results in
6040-
undefined behavior\ubdef{class.cdtor.before.ctor.after.dtor}. For an object with a non-trivial destructor, referring to
6040+
undefined behavior\ubdef{class.cdtor.before.ctor}.
6041+
For an object with a non-trivial destructor, referring to
60416042
any non-static member or base class of the object after the destructor finishes
6042-
execution results in undefined behavior.
6043+
execution results in undefined behavior\ubdef{class.cdtor.after.dtor}.
60436044
\begin{example}
60446045
\begin{codeblock}
60456046
struct X { int i; };

source/declarations.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,11 +3285,11 @@
32853285
the converted initializer is a glvalue whose
32863286
type is not call-compatible\iref{expr.call}
32873287
with the type of the function's definition
3288-
results in undefined behavior.
3288+
results in undefined behavior.\ubdef{dcl.ref.incompatible.function}
32893289
Attempting to bind a reference to an object where
32903290
the converted initializer is a glvalue through which
32913291
the object is not type-accessible\iref{basic.lval}
3292-
results in undefined behavior.
3292+
results in undefined behavior\ubdef{dcl.ref.incompatible.type}.
32933293
\begin{note}
32943294
\indextext{reference!null}%
32953295
The object designated by such a glvalue can be
@@ -3303,7 +3303,7 @@
33033303
\end{note}
33043304
The behavior of an evaluation of a reference\iref{expr.prim.id, expr.ref} that
33053305
does not happen after\iref{intro.races} the initialization of the reference
3306-
is undefined.
3306+
is undefined.\ubdef{dcl.ref.uninitialized.reference}
33073307
\begin{example}
33083308
\begin{codeblock}
33093309
int &f(int&);

source/expressions.tex

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
a defaulted copy/move constructor or copy/move assignment operator
327327
for a union of type \tcode{U} with a glvalue argument
328328
that does not denote an object of type \cv{}~\tcode{U} within its lifetime,
329-
the behavior is undefined.
329+
the behavior is undefined.\ubdef{expr.basic.lvalue.union.initialization}
330330
\begin{note}
331331
In C, an entire object of structure type can be accessed, e.g., using assignment.
332332
By contrast, \Cpp{} has no notion of accessing an object of class type
@@ -345,7 +345,7 @@
345345
If a pointer to $X$ would be valid in
346346
the context of the evaluation of the expression\iref{basic.fundamental},
347347
the result designates $X$;
348-
otherwise, the behavior is undefined.
348+
otherwise, the behavior is undefined.\ubdef{expr.type.reference.lifetime}
349349
\begin{note}
350350
Before the lifetime of the reference has started or after it has ended,
351351
the behavior is undefined (see~\ref{basic.life}).
@@ -686,7 +686,7 @@
686686

687687
\item Otherwise, if the bits in the value representation of
688688
the object to which the glvalue refers
689-
are not valid for the object's type, the behavior is undefined.
689+
are not valid for the object's type, the behavior is undefined.\ubdef{conv.lval.valid.representation}
690690
\begin{example}
691691
\begin{codeblock}
692692
bool f() {
@@ -1003,7 +1003,7 @@
10031003
integer type. The conversion truncates; that is, the fractional part is
10041004
discarded.
10051005
\indextext{value!undefined unrepresentable integral}%
1006-
The behavior is undefined\ubdef{conv.fpint.not.represented} if the truncated value cannot be represented
1006+
The behavior is undefined\ubdef{conv.fpint.float.not.represented} if the truncated value cannot be represented
10071007
in the destination type.
10081008
\begin{note}
10091009
If the destination type is \keyword{bool}, see~\ref{conv.bool}.
@@ -1024,7 +1024,8 @@
10241024
exactly as a value of the floating-point type.
10251025
\end{note}
10261026
If the value being converted is
1027-
outside the range of values that can be represented, the behavior is undefined. If the
1027+
outside the range of values that can be represented, the behavior is undefined.\ubdef{conv.fpint.int.not.represented}
1028+
If the
10281029
source type is \keyword{bool}, the value \keyword{false} is converted to zero and the value
10291030
\keyword{true} is converted to one.
10301031

@@ -1077,7 +1078,7 @@
10771078
that is
10781079
within its lifetime or
10791080
within its period of construction or destruction\iref{class.cdtor},
1080-
the behavior is undefined.
1081+
the behavior is undefined.\ubdef{conv.ptr.virtual.base}
10811082
Otherwise,
10821083
the result is a pointer to the base class subobject of
10831084
the derived class object.
@@ -1111,7 +1112,8 @@
11111112
\tcode{D}, a program that necessitates this conversion is ill-formed.
11121113
If class \tcode{D} does not contain the original member and
11131114
is not a base class of the class containing the original member,
1114-
the behavior is undefined. Otherwise,
1115+
the behavior is undefined.\ubdef{conv.member.missing.member}
1116+
Otherwise,
11151117
the result of the conversion refers to the same member as the pointer to
11161118
member before the conversion took place, but it refers to the base class
11171119
member as if it were a member of the derived class. The result refers to
@@ -4392,7 +4394,7 @@
43924394
or direct base class relationship and
43934395
the result of \tcode{E1} is an object whose type
43944396
is not similar\iref{conv.qual} to the type of \tcode{E1},
4395-
the behavior is undefined\ubdef{expr.ref.not.similar}.
4397+
the behavior is undefined\ubdef{expr.ref.member.not.similar}.
43964398
\begin{example}
43974399
\begin{codeblock}
43984400
struct A { int i; };
@@ -4528,7 +4530,7 @@
45284530
that is
45294531
within its lifetime or
45304532
within its period of construction or destruction,
4531-
the behavior is undefined.
4533+
the behavior is undefined.\ubdef{expr.dynamic.cast.lifetime}
45324534

45334535
\pnum
45344536
If \tcode{T} is ``pointer to \cv{} \keyword{void}'', then the result
@@ -4848,7 +4850,7 @@
48484850
the result of the conversion is
48494851
an \impldef{result of inexact floating-point conversion} choice of
48504852
either of those values.
4851-
Otherwise, the behavior is undefined\ubdef{expr.static.cast.downcast.wrong.derived.type}.
4853+
Otherwise, the behavior is undefined\ubdef{expr.static.cast.fp.outside.range}.
48524854

48534855
\pnum
48544856
\indextext{cast!base class}%
@@ -4869,7 +4871,7 @@
48694871
``pointer to \cvqual{cv1} \tcode{B}'' points to a \tcode{B} that is
48704872
actually a base class subobject of an object of type \tcode{D}, the resulting
48714873
pointer points to the enclosing object of type \tcode{D}. Otherwise, the
4872-
behavior is undefined.
4874+
behavior is undefined\ubdef{expr.static.cast.downcast.wrong.derived.type}.
48734875

48744876
\pnum
48754877
\indextext{cast!pointer-to-member}%
@@ -5270,7 +5272,8 @@
52705272
The operator yields an lvalue of type \tcode{T}.
52715273
If the operand points to an object or function,
52725274
the result denotes that object or function;
5273-
otherwise, the behavior is undefined except as specified in \ref{expr.typeid}.
5275+
otherwise, the behavior is undefined except as specified in \ref{expr.typeid}
5276+
\ubdef{expr.unary.dereference}.
52745277
\begin{note}
52755278
Indirection through a pointer to an out-of-lifetime object is valid\iref{basic.life}.
52765279
\end{note}
@@ -7340,7 +7343,7 @@
73407343
\pnum
73417344
For addition or subtraction, if the expressions \tcode{P} or \tcode{Q} have
73427345
type ``pointer to \cv{}~\tcode{T}'', where \tcode{T} and the array element type
7343-
are not similar\iref{conv.qual}, the behavior is undefined\ubdef{expr.add.polymorphic}.
7346+
are not similar\iref{conv.qual}, the behavior is undefined\ubdef{expr.add.not.similar}.
73447347
\begin{example}
73457348
\begin{codeblock}
73467349
int arr[5] = {1, 2, 3, 4, 5};

0 commit comments

Comments
 (0)