Skip to content

Commit 458b16a

Browse files
authored
Merge 2025-02 CWG Motion 4
P1494R5 Partial program correctness
2 parents 3095e14 + debf098 commit 458b16a

File tree

5 files changed

+71
-16
lines changed

5 files changed

+71
-16
lines changed

source/intro.tex

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -919,23 +919,41 @@
919919
Certain other operations are described in this document as
920920
undefined behavior (for example, the effect of
921921
attempting to modify a const object).
922+
923+
\pnum
924+
Certain events in the execution of a program
925+
are termed \defnadj{observable}{checkpoints}.
922926
\begin{note}
923-
This document imposes no requirements on the
924-
behavior of programs that contain undefined behavior.
927+
A call to \tcode{std::observable}\iref{utility.undefined}
928+
is an observable checkpoint.
925929
\end{note}
926930

927931
\pnum
928932
\indextext{program!well-formed}%
929933
\indextext{behavior!observable}%
934+
The \defnadj{defined}{prefix} of an execution
935+
comprises the operations $O$
936+
for which for every undefined operation $U$
937+
there is an observable checkpoint $C$
938+
such that $O$ happens before $C$ and
939+
$C$ happens before $U$.
940+
941+
\begin{note}
942+
The undefined behavior that arises from a data race\iref{intro.races}
943+
occurs on all participating threads.
944+
\end{note}
945+
930946
A conforming implementation executing a well-formed program shall
931-
produce the same observable behavior as one of the possible executions
932-
of the corresponding instance of the abstract machine with the
947+
produce the observable behavior
948+
of the defined prefix
949+
of one of the possible executions
950+
of the corresponding instance
951+
of the abstract machine with the
933952
same program and the same input.
934953
\indextext{behavior!undefined}%
935-
However, if any such execution contains an undefined operation, this document places no
936-
requirement on the implementation executing that program with that input
937-
(not even with regard to operations preceding the first undefined
938-
operation).
954+
If the selected execution contains an undefined operation,
955+
the implementation executing that program with that input
956+
may produce arbitrary additional observable behavior afterwards.
939957
If the execution contains an operation specified as having erroneous behavior,
940958
the implementation is permitted to issue a diagnostic and
941959
is permitted to terminate the execution
@@ -953,23 +971,28 @@
953971

954972
\pnum
955973
\indextext{conformance requirements}%
956-
The least requirements on a conforming implementation are:
974+
The following specify the
975+
\defnadj{observable}{behavior}
976+
of the program:
957977
\begin{itemize}
958978
\item
959979
Accesses through volatile glvalues are evaluated strictly according to the
960980
rules of the abstract machine.
961981
\item
962-
At program termination, all data written into files shall be
963-
identical to one of the possible results that execution of the program
964-
according to the abstract semantics would have produced.
982+
Data is delivered to the host environment to be written into files (\xrefc{7.21.3}).
983+
984+
\begin{note}
985+
Delivering such data
986+
is followed by an observable checkpoint\iref{cstdio.syn}.
987+
Not all host environments provide access to file contents before program termination.
988+
\end{note}
989+
965990
\item
966991
The input and output dynamics of interactive devices shall take
967992
place in such a fashion that prompting output is actually delivered before a program waits for input. What constitutes an interactive device is
968993
\impldef{interactive device}.
969994
\end{itemize}
970995

971-
These collectively are referred to as the
972-
\defnx{observable behavior}{behavior!observable} of the program.
973996
\begin{note}
974997
More stringent correspondences between abstract and actual
975998
semantics can be defined by each implementation.

source/iostreams.tex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@
480480
declares objects that associate objects with the
481481
standard C streams provided for by the functions declared in
482482
\libheader{cstdio}, and includes all the headers necessary to use these objects.
483+
The dynamic types of the stream buffers
484+
initially associated with these objects are unspecified,
485+
but they have the behavior specified for
486+
\tcode{std::basic_filebuf<char>}
487+
or
488+
\tcode{std::basic_filebuf<wchar_t>}.
483489

484490
\pnum
485491
The objects are constructed and the associations are established at some
@@ -6872,6 +6878,7 @@
68726878
if \tcode{out} contains invalid code units,
68736879
\indextext{undefined}%
68746880
the behavior is undefined.
6881+
Then establishes an observable checkpoint\iref{intro.abstract}.
68756882
\item
68766883
Otherwise
68776884
inserts the character sequence
@@ -7852,6 +7859,7 @@
78527859
if \tcode{out} contains invalid code units,
78537860
\indextext{undefined}%
78547861
the behavior is undefined.
7862+
Then establishes an observable checkpoint\iref{intro.abstract}.
78557863
\item
78567864
Otherwise writes \tcode{out} to \tcode{stream} unchanged.
78577865
\end{itemize}
@@ -11571,6 +11579,7 @@
1157111579
At this point if \tcode{b != p} and \tcode{b == end} (\tcode{xbuf} isn't large
1157211580
enough) then increase \tcode{XSIZE} and repeat from the beginning.
1157311581
\end{itemize}
11582+
Then establishes an observable checkpoint\iref{intro.abstract}.
1157411583

1157511584
\pnum
1157611585
\returns
@@ -18941,6 +18950,13 @@
1894118950
The contents and meaning of the header \libheader{cstdio}
1894218951
are the same as the C standard library header \libheader{stdio.h}.
1894318952

18953+
\pnum
18954+
The return from each function call
18955+
that delivers data
18956+
to the host environment
18957+
to be written to a file (\xrefc{7.21.3})
18958+
is an observable checkpoint\iref{intro.abstract}.
18959+
1894418960
\pnum
1894518961
Calls to the function \tcode{tmpnam} with an argument that is a null pointer value may
1894618962
introduce a data race\iref{res.on.data.races} with other calls to \tcode{tmpnam} with

source/utilities.tex

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@
9393
template<class T>
9494
constexpr underlying_type_t<T> to_underlying(T value) noexcept;
9595

96-
// \ref{utility.unreachable}, unreachable
96+
// \ref{utility.undefined}, undefined behavior
9797
[[noreturn]] void unreachable();
98+
void observable() noexcept;
9899

99100
// \ref{intseq}, compile-time integer sequences%
100101
\indexlibraryglobal{index_sequence}%
@@ -670,7 +671,7 @@
670671
\tcode{static_cast<underlying_type_t<T>>(value)}.
671672
\end{itemdescr}
672673

673-
\rSec2[utility.unreachable]{Function \tcode{unreachable}}
674+
\rSec2[utility.undefined]{Undefined behavior}
674675

675676
\indexlibraryglobal{unreachable}%
676677
\begin{itemdecl}
@@ -704,6 +705,17 @@
704705
\end{example}
705706
\end{itemdescr}
706707

708+
\indexlibraryglobal{observable}%
709+
\begin{itemdecl}
710+
void observable() noexcept;
711+
\end{itemdecl}
712+
713+
\begin{itemdescr}
714+
\pnum
715+
\effects
716+
Establishes an observable checkpoint\iref{intro.abstract}.
717+
\end{itemdescr}
718+
707719
\rSec1[pairs]{Pairs}
708720

709721
\rSec2[pairs.general]{General}

source/xrefdelta.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@
487487
\movedxref{stmt.stmt}{stmt}
488488
\movedxref{dcl.dcl}{dcl}
489489

490+
% P1494R5 added more to this section and expanded its scope
491+
\movedxref{utility.unreachable}{utility.undefined}
492+
490493
%%% Deprecated features.
491494
%%% Example:
492495
%

source/xrefprev

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,6 +2700,7 @@ utility.requirements
27002700
utility.swap
27012701
utility.syn
27022702
utility.to.chars
2703+
utility.unreachable
27032704
valarray.access
27042705
valarray.assign
27052706
valarray.binary

0 commit comments

Comments
 (0)