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} 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