Skip to content

Commit 31df2c8

Browse files
committed
P3471R4 Standard library hardening
1 parent 805aac8 commit 31df2c8

File tree

8 files changed

+156
-79
lines changed

8 files changed

+156
-79
lines changed

source/containers.tex

+50-32
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,10 @@
18611861
\result
18621862
\tcode{reference; const_reference} for constant \tcode{a}.
18631863

1864+
\pnum
1865+
\hardexpects
1866+
\tcode{a.empty()} is \tcode{false}.
1867+
18641868
\pnum
18651869
\returns
18661870
\tcode{*a.begin()}
@@ -1886,6 +1890,10 @@
18861890
\result
18871891
\tcode{reference; const_reference} for constant \tcode{a}.
18881892

1893+
\pnum
1894+
\hardexpects
1895+
\tcode{a.empty()} is \tcode{false}.
1896+
18891897
\pnum
18901898
\effects
18911899
Equivalent to:
@@ -2150,7 +2158,7 @@
21502158
\keyword{void}
21512159

21522160
\pnum
2153-
\expects
2161+
\hardexpects
21542162
\tcode{a.empty()} is \tcode{false}.
21552163

21562164
\pnum
@@ -2175,7 +2183,7 @@
21752183
\keyword{void}
21762184

21772185
\pnum
2178-
\expects
2186+
\hardexpects
21792187
\tcode{a.empty()} is \tcode{false}.
21802188

21812189
\pnum
@@ -2201,6 +2209,10 @@
22012209
\result
22022210
\tcode{reference; const_reference} for constant \tcode{a}.
22032211

2212+
\pnum
2213+
\hardexpects
2214+
\tcode{n < a.size()} is \tcode{true}.
2215+
22042216
\pnum
22052217
\effects
22062218
Equivalent to: \tcode{return *(a.begin() + n);}
@@ -19112,11 +19124,13 @@
1911219124
\begin{itemize}
1911319125
\item \range{first}{first + count} is a valid range.
1911419126
\item \tcode{It} models \libconcept{contiguous_iterator}.
19115-
\item
19116-
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19117-
then \tcode{count} is equal to \tcode{extent}.
1911819127
\end{itemize}
1911919128

19129+
\pnum
19130+
\hardexpects
19131+
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19132+
then \tcode{count == extent} is \tcode{true}.
19133+
1912019134
\pnum
1912119135
\effects
1912219136
Initializes \exposid{data_} with \tcode{to_address(first)} and
@@ -19152,14 +19166,16 @@
1915219166
\pnum
1915319167
\expects
1915419168
\begin{itemize}
19155-
\item
19156-
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19157-
then \tcode{last - first} is equal to \tcode{extent}.
1915819169
\item \range{first}{last} is a valid range.
1915919170
\item \tcode{It} models \libconcept{contiguous_iterator}.
1916019171
\item \tcode{End} models \tcode{\libconcept{sized_sentinel_for}<It>}.
1916119172
\end{itemize}
1916219173

19174+
\pnum
19175+
\hardexpects
19176+
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19177+
then \tcode{(last - first) == extent} is \tcode{true}.
19178+
1916319179
\pnum
1916419180
\effects
1916519181
Initializes \exposid{data_} with \tcode{to_address(first)} and
@@ -19230,14 +19246,17 @@
1923019246
\pnum
1923119247
\expects
1923219248
\begin{itemize}
19233-
\item If \tcode{extent} is not equal to \tcode{dynamic_extent},
19234-
then \tcode{ranges::size(r)} is equal to \tcode{extent}.
1923519249
\item \tcode{R} models \tcode{ranges::\libconcept{contiguous_range}} and
1923619250
\tcode{ranges::\libconcept{sized_range}}.
1923719251
\item If \tcode{is_const_v<element_type>} is \tcode{false},
1923819252
\tcode{R} models \tcode{ranges::\libconcept{borrowed_range}}.
1923919253
\end{itemize}
1924019254

19255+
\pnum
19256+
\hardexpects
19257+
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19258+
then \tcode{ranges::size(r) == extent} is \tcode{true}.
19259+
1924119260
\pnum
1924219261
\effects
1924319262
Initializes \exposid{data_} with \tcode{ranges::data(r)} and
@@ -19259,9 +19278,9 @@
1925919278
\tcode{is_const_v<element_type>} is \tcode{true}.
1926019279

1926119280
\pnum
19262-
\expects
19263-
If \tcode{extent} is not equal to \tcode{dynamic_extent}, then
19264-
\tcode{il.size()} is equal to \tcode{extent}.
19281+
\hardexpects
19282+
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19283+
then \tcode{il.size() == extent} is \tcode{true}.
1926519284

1926619285
\pnum
1926719286
\effects
@@ -19299,9 +19318,9 @@
1929919318
\end{itemize}
1930019319

1930119320
\pnum
19302-
\expects
19321+
\hardexpects
1930319322
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19304-
then \tcode{s.size()} is equal to \tcode{extent}.
19323+
then \tcode{s.size() == extent} is \tcode{true}.
1930519324

1930619325
\pnum
1930719326
\effects
@@ -19371,7 +19390,7 @@
1937119390
\tcode{Count <= Extent} is \tcode{true}.
1937219391

1937319392
\pnum
19374-
\expects
19393+
\hardexpects
1937519394
\tcode{Count <= size()} is \tcode{true}.
1937619395

1937719396
\pnum
@@ -19391,7 +19410,7 @@
1939119410
\tcode{Count <= Extent} is \tcode{true}.
1939219411

1939319412
\pnum
19394-
\expects
19413+
\hardexpects
1939519414
\tcode{Count <= size()} is \tcode{true}.
1939619415

1939719416
\pnum
@@ -19415,7 +19434,7 @@
1941519434
is \tcode{true}.
1941619435

1941719436
\pnum
19418-
\expects
19437+
\hardexpects
1941919438
\begin{codeblock}
1942019439
Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset)
1942119440
\end{codeblock}
@@ -19446,7 +19465,7 @@
1944619465

1944719466
\begin{itemdescr}
1944819467
\pnum
19449-
\expects
19468+
\hardexpects
1945019469
\tcode{count <= size()} is \tcode{true}.
1945119470

1945219471
\pnum
@@ -19461,7 +19480,7 @@
1946119480

1946219481
\begin{itemdescr}
1946319482
\pnum
19464-
\expects
19483+
\hardexpects
1946519484
\tcode{count <= size()} is \tcode{true}.
1946619485

1946719486
\pnum
@@ -19477,7 +19496,7 @@
1947719496

1947819497
\begin{itemdescr}
1947919498
\pnum
19480-
\expects
19499+
\hardexpects
1948119500
\begin{codeblock}
1948219501
offset <= size() && (count == dynamic_extent || count <= size() - offset)
1948319502
\end{codeblock}
@@ -19535,7 +19554,7 @@
1953519554

1953619555
\begin{itemdescr}
1953719556
\pnum
19538-
\expects
19557+
\hardexpects
1953919558
\tcode{idx < size()} is \tcode{true}.
1954019559

1954119560
\pnum
@@ -19569,7 +19588,7 @@
1956919588

1957019589
\begin{itemdescr}
1957119590
\pnum
19572-
\expects
19591+
\hardexpects
1957319592
\tcode{empty()} is \tcode{false}.
1957419593

1957519594
\pnum
@@ -19588,7 +19607,7 @@
1958819607

1958919608
\begin{itemdescr}
1959019609
\pnum
19591-
\expects
19610+
\hardexpects
1959219611
\tcode{empty()} is \tcode{false}.
1959319612

1959419613
\pnum
@@ -23755,17 +23774,16 @@
2375523774

2375623775
\pnum
2375723776
\expects
23758-
\begin{itemize}
23759-
\item
23760-
For each rank index \tcode{r} of \tcode{extents_type},
23761-
\tcode{static_extent(r) == dynamic_extent || static_extent(r) == other.extent(r)}
23762-
is \tcode{true}.
23763-
\item
2376423777
$[0, \tcode{\exposid{map_}.required_span_size()})$ is
2376523778
an accessible range of \exposid{ptr_} and \exposid{acc_}
2376623779
for values of \exposid{ptr_}, \exposid{map_}, and \exposid{acc_}
2376723780
after the invocation of this constructor.
23768-
\end{itemize}
23781+
23782+
\pnum
23783+
\hardexpects
23784+
For each rank index \tcode{r} of \tcode{extents_type},
23785+
\tcode{static_extent(r) == dynamic_extent || static_extent(r) == other.extent(r)}
23786+
is \tcode{true}.
2376923787

2377023788
\pnum
2377123789
\effects
@@ -23811,7 +23829,7 @@
2381123829
Let \tcode{I} be \tcode{extents_type::\exposid{index-cast}(std::move(indices))}.
2381223830

2381323831
\pnum
23814-
\expects
23832+
\hardexpects
2381523833
\tcode{I} is a multidimensional index in \tcode{extents()}.
2381623834
\begin{note}
2381723835
This implies that

source/intro.tex

+11-1
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,8 @@
822822
\indextext{conformance requirements!library|)}
823823

824824
\pnum
825-
Two kinds of implementations are defined: a \defnadj{hosted}{implementation} and a
825+
An implementation is either a
826+
\defnadj{hosted}{implementation} or a
826827
\defnadj{freestanding}{implementation}.
827828
A freestanding
828829
implementation is one in which execution may take place without the benefit of
@@ -834,6 +835,15 @@
834835
described in \ref{lex} through \ref{\lastcorechapter} and
835836
the subset of the library facilities described in \ref{compliance}.
836837

838+
\pnum
839+
It is
840+
\impldef{whether the implementation is a hardened implementation}
841+
whether the implementation is a
842+
\defnadj{hardened}{implementation}.
843+
If it is a hardened implementation,
844+
violating a hardened precondition
845+
results in a contract violation\iref{structure.specifications}.
846+
837847
\pnum
838848
An implementation is encouraged to document its limitations in
839849
the size or complexity of the programs it can successfully process,

source/lib-intro.tex

+32-5
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,28 @@
370370

371371
\item
372372
\expects
373-
the conditions
374-
that the function assumes to hold whenever it is called;
373+
conditions that the function assumes to hold whenever it is called;
375374
violation of any preconditions results in undefined behavior.
376375

376+
\item
377+
\hardexpects
378+
conditions that the function assumes to hold whenever it is called.
379+
\begin{itemize}
380+
\item
381+
When invoking the function in a hardened implementation,
382+
prior to any other observable side effects of the function,
383+
one or more contract assertions
384+
whose predicates are as described in the hardened precondition
385+
are evaluated with a checking semantic\iref{basic.contract.eval}.
386+
If any of these assertions is evaluated with a non-terminating semantic
387+
and the contract-violation handler returns,
388+
the program has undefined behavior.
389+
\item
390+
When invoking the function in a non-hardened implementation,
391+
if any hardened precondition is violated,
392+
the program has undefined behavior.
393+
\end{itemize}
394+
377395
\item
378396
\effects
379397
the actions performed by the function.
@@ -424,9 +442,18 @@
424442
If \tcode{F}'s semantics specifies any \Fundescx{Constraints} or \Fundescx{Mandates} elements,
425443
then those requirements are logically imposed prior to the \term{equivalent-to} semantics.
426444
Next, the semantics of the code sequence are determined by the
427-
\Fundescx{Constraints}, \Fundescx{Mandates}, \Fundescx{Preconditions}, \Fundescx{Effects},
428-
\Fundescx{Synchronization}, \Fundescx{Postconditions}, \Fundescx{Returns}, \Fundescx{Throws},
429-
\Fundescx{Complexity}, \Fundescx{Remarks}, and \Fundescx{Error conditions}
445+
\Fundescx{Constraints},
446+
\Fundescx{Mandates},
447+
\Fundescx{Preconditions},
448+
\Fundescx{Hardened preconditions},
449+
\Fundescx{Effects},
450+
\Fundescx{Synchronization},
451+
\Fundescx{Postconditions},
452+
\Fundescx{Returns},
453+
\Fundescx{Throws},
454+
\Fundescx{Complexity},
455+
\Fundescx{Remarks}, and
456+
\Fundescx{Error conditions}
430457
specified for the function invocations contained in the code sequence.
431458
The value returned from \tcode{F} is specified by \tcode{F}'s \Fundescx{Returns} element,
432459
or if \tcode{F} has no \Fundescx{Returns} element,

source/macros.tex

+1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@
366366
\newcommand{\constraints}{\Fundesc{Constraints}}
367367
\newcommand{\mandates}{\Fundesc{Mandates}}
368368
\newcommand{\expects}{\Fundesc{Preconditions}}
369+
\newcommand{\hardexpects}{\Fundesc{Hardened preconditions}}
369370
\newcommand{\effects}{\Fundesc{Effects}}
370371
\newcommand{\ensures}{\Fundesc{Postconditions}}
371372
\newcommand{\returns}{\Fundesc{Returns}}

source/numerics.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -7494,7 +7494,7 @@
74947494

74957495
\begin{itemdescr}
74967496
\pnum
7497-
\expects
7497+
\hardexpects
74987498
\tcode{n < size()} is \tcode{true}.
74997499

75007500
\pnum

0 commit comments

Comments
 (0)