From 7bf091d19dc4e83f1b28a6f383bbc476b59712c5 Mon Sep 17 00:00:00 2001 From: notadragon Date: Fri, 23 May 2025 14:16:55 -0400 Subject: [PATCH 1/2] [ub] small fixes to examples --- source/ub.tex | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/source/ub.tex b/source/ub.tex index fa3e3f42a3..11de730698 100644 --- a/source/ub.tex +++ b/source/ub.tex @@ -790,9 +790,13 @@ \pnum \begin{example} +If \tcode{float} does not adhere to \IsoFloatUndated{} +and cannot represent positive infinty, +a sufficiently large \tcode{double} value will be +outside the (finite) range of \tcode{float}. \begin{codeblock} void f() { - double d = FLT_MAX * 16; + double d = FLT_MAX; d *= 16; float f = static_cast(d); // undefined behavior. } @@ -800,13 +804,6 @@ \end{example} -\pnum -\begin{example} -\begin{codeblock} - -\end{codeblock} -\end{example} - \pnum \ubxref{expr.static.cast.downcast.wrong.derived.type} \\ Down-casting to the wrong derived type is undefined behavior. @@ -1347,7 +1344,8 @@ \begin{codeblock} extern int &ir1; int i2 = ir1; // undefined behavior, \tcode{ir1} not yet initialized -int ir1 = 17; +int i3 = 17; +int &ir1 = i3; \end{codeblock} \end{example} @@ -1674,9 +1672,9 @@ } void f() { - X& px = &g(); + X* px = &g(); px->~X(); - int*p = px->i; // undefined behavior + int p = px->i; // undefined behavior } \end{codeblock} \end{example} From a0b47c4413a2958f931d591878bda6049849b1be Mon Sep 17 00:00:00 2001 From: notadragon Date: Fri, 23 May 2025 20:53:17 -0400 Subject: [PATCH 2/2] fixup: herb suggestion for variable name --- source/ub.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/ub.tex b/source/ub.tex index 11de730698..5dc126bab8 100644 --- a/source/ub.tex +++ b/source/ub.tex @@ -1674,7 +1674,7 @@ { X* px = &g(); px->~X(); - int p = px->i; // undefined behavior + int j = px->i; // undefined behavior } \end{codeblock} \end{example}