From 3ae98dedb9d307624cc6c645f3b4130289b50d54 Mon Sep 17 00:00:00 2001 From: Dawn Perchik Date: Sat, 21 Nov 2026 16:26:46 -0800 Subject: [PATCH 1/2] CWG3232 Accidental removal of undefined behavior in pointer subtraction Editorial notes: * Stable label [ub:expr.sub.pointers.rep] renamed to [ub:expr.add.sub.pointers.rep], similar to existing cases (the reference is to "expr.add"). * "is undefined behavior" changed to the more customary "has undefined behavior". --- source/expressions.tex | 8 +++----- source/ub.tex | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/source/expressions.tex b/source/expressions.tex index 009f0055ea..94e42a5a77 100644 --- a/source/expressions.tex +++ b/source/expressions.tex @@ -7490,13 +7490,11 @@ \item Otherwise, if \tcode{P} and \tcode{Q} point to, respectively, array elements $i$ and $j$ of the same array object \tcode{x}, -the expression \tcode{P - Q} has the value $i - j$. -\begin{note} -If the value $i - j$ +the expression \tcode{P - Q} has the value $i - j$; +if that value is not in the range of representable values of type \tcode{std::ptrdiff_t}, -the behavior is undefined\iref{expr.pre}. -\end{note} +the behavior is undefined\ubdef{expr.add.sub.pointers.rep}. \item Otherwise, the behavior is undefined\ubdef{expr.add.sub.diff.pointers}. \end{itemize} diff --git a/source/ub.tex b/source/ub.tex index 2e7b9d8590..ac6ce57ade 100644 --- a/source/ub.tex +++ b/source/ub.tex @@ -1228,6 +1228,21 @@ \end{codeblock} \end{example} +\ubdescription{expr.add.sub.pointers.rep} + +\pnum +Subtracting two expressions of pointer type +where the difference is not representable in \tcode{std::ptrdiff_t} +has undefined behavior. + +\pnum +\begin{example} +\begin{codeblock} +char big[static_cast(PTRDIFF_MAX) + 1]; +std::ptrdiff_t d = (big + sizeof(big) - big); // undefined behavior +\end{codeblock} +\end{example} + \ubdescription{expr.add.sub.diff.pointers} \pnum From 774b8174867ff941a892108f4313fb7e53afd1d4 Mon Sep 17 00:00:00 2001 From: Dawn Perchik Date: Sat, 21 Nov 2026 16:31:30 -0800 Subject: [PATCH 2/2] CWG3233 Function contract assertions are needed for pure virtual function calls --- source/declarations.tex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/declarations.tex b/source/declarations.tex index 47a12faf1f..701acf1628 100644 --- a/source/declarations.tex +++ b/source/declarations.tex @@ -4880,7 +4880,9 @@ are considered to be \defnx{needed}{needed!function contract assertion}\iref{temp.inst} when \begin{itemize} \item -the function is odr-used\iref{basic.def.odr} or +the function is odr-used\iref{basic.def.odr}, +\item +the function is declared as a virtual function\iref{class.abstract}, or \item the function is defined. \end{itemize}