Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/declarations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
8 changes: 3 additions & 5 deletions source/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
15 changes: 15 additions & 0 deletions source/ub.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uintmax_t>(PTRDIFF_MAX) + 1];
std::ptrdiff_t d = (big + sizeof(big) - big); // undefined behavior
\end{codeblock}
\end{example}

\ubdescription{expr.add.sub.diff.pointers}

\pnum
Expand Down
Loading