Skip to content

Commit b474a81

Browse files
committed
P1494R5 Partial program correctness
1 parent 10468bf commit b474a81

File tree

3 files changed

+67
-16
lines changed

3 files changed

+67
-16
lines changed

source/intro.tex

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -919,23 +919,42 @@
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+
\indextext{observable checkpoint}
925+
Certain events in the execution of a program
926+
are termed \defn{observable checkpoints}.
922927
\begin{note}
923-
This document imposes no requirements on the
924-
behavior of programs that contain undefined behavior.
928+
A call to \tcode{std::observable}\iref{utility.undefined}
929+
is an observable checkpoint.
925930
\end{note}
926931

927932
\pnum
928933
\indextext{program!well-formed}%
929934
\indextext{behavior!observable}%
935+
The \defn{defined prefix} of an execution
936+
comprises the operations $O$
937+
for which for every undefined operation $U$
938+
there is an observable checkpoint $C$
939+
such that $O$ happens before $C$ and
940+
$C$ happens before $U$.
941+
942+
\begin{note}
943+
The undefined behavior that arises from a data race\iref{intro.races}
944+
occurs on all participating threads.
945+
\end{note}
946+
930947
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
948+
produce the observable behavior
949+
of the defined prefix
950+
of one of the possible executions
951+
of the corresponding instance
952+
of the abstract machine with the
933953
same program and the same input.
934954
\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).
955+
If the selected execution contains an undefined operation,
956+
the implementation executing that program with that input
957+
may produce arbitrary additional observable behavior aferwards.
939958
If the execution contains an operation specified as having erroneous behavior,
940959
the implementation is permitted to issue a diagnostic and
941960
is permitted to terminate the execution
@@ -953,23 +972,28 @@
953972

954973
\pnum
955974
\indextext{conformance requirements}%
956-
The least requirements on a conforming implementation are:
975+
The following specify the
976+
\defnx{observable behavior}{behavior!observable}
977+
of the program:
957978
\begin{itemize}
958979
\item
959980
Accesses through volatile glvalues are evaluated strictly according to the
960981
rules of the abstract machine.
961982
\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.
983+
Data is delivered to the host environment to be written into files (\xrefc{7.21.3}).
984+
985+
\begin{note}
986+
Delivering such data
987+
is followed by an observable checkpoint\iref{cstdio.syn}.
988+
Not all host environments provide access to file contents before program termination.
989+
\end{note}
990+
965991
\item
966992
The input and output dynamics of interactive devices shall take
967993
place in such a fashion that prompting output is actually delivered before a program waits for input. What constitutes an interactive device is
968994
\impldef{interactive device}.
969995
\end{itemize}
970996

971-
These collectively are referred to as the
972-
\defnx{observable behavior}{behavior!observable} of the program.
973997
\begin{note}
974998
More stringent correspondences between abstract and actual
975999
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: 13 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,16 @@
704705
\end{example}
705706
\end{itemdescr}
706707

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

709720
\rSec2[pairs.general]{General}

0 commit comments

Comments
 (0)