Skip to content

Commit b37eb4c

Browse files
authored
Merge 2025-02 LWG Motion 15
P3471R4 Standard library hardening
2 parents 240e01c + 96e1c68 commit b37eb4c

File tree

8 files changed

+158
-81
lines changed

8 files changed

+158
-81
lines changed

source/containers.tex

+50-32
Original file line numberDiff line numberDiff line change
@@ -1879,6 +1879,10 @@
18791879
\result
18801880
\tcode{reference; const_reference} for constant \tcode{a}.
18811881

1882+
\pnum
1883+
\hardexpects
1884+
\tcode{a.empty()} is \tcode{false}.
1885+
18821886
\pnum
18831887
\returns
18841888
\tcode{*a.begin()}
@@ -1904,6 +1908,10 @@
19041908
\result
19051909
\tcode{reference; const_reference} for constant \tcode{a}.
19061910

1911+
\pnum
1912+
\hardexpects
1913+
\tcode{a.empty()} is \tcode{false}.
1914+
19071915
\pnum
19081916
\effects
19091917
Equivalent to:
@@ -2168,7 +2176,7 @@
21682176
\keyword{void}
21692177

21702178
\pnum
2171-
\expects
2179+
\hardexpects
21722180
\tcode{a.empty()} is \tcode{false}.
21732181

21742182
\pnum
@@ -2193,7 +2201,7 @@
21932201
\keyword{void}
21942202

21952203
\pnum
2196-
\expects
2204+
\hardexpects
21972205
\tcode{a.empty()} is \tcode{false}.
21982206

21992207
\pnum
@@ -2219,6 +2227,10 @@
22192227
\result
22202228
\tcode{reference; const_reference} for constant \tcode{a}.
22212229

2230+
\pnum
2231+
\hardexpects
2232+
\tcode{n < a.size()} is \tcode{true}.
2233+
22222234
\pnum
22232235
\effects
22242236
Equivalent to: \tcode{return *(a.begin() + n);}
@@ -19233,11 +19245,13 @@
1923319245
\begin{itemize}
1923419246
\item \range{first}{first + count} is a valid range.
1923519247
\item \tcode{It} models \libconcept{contiguous_iterator}.
19236-
\item
19237-
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19238-
then \tcode{count} is equal to \tcode{extent}.
1923919248
\end{itemize}
1924019249

19250+
\pnum
19251+
\hardexpects
19252+
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19253+
then \tcode{count == extent} is \tcode{true}.
19254+
1924119255
\pnum
1924219256
\effects
1924319257
Initializes \exposid{data_} with \tcode{to_address(first)} and
@@ -19273,14 +19287,16 @@
1927319287
\pnum
1927419288
\expects
1927519289
\begin{itemize}
19276-
\item
19277-
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19278-
then \tcode{last - first} is equal to \tcode{extent}.
1927919290
\item \range{first}{last} is a valid range.
1928019291
\item \tcode{It} models \libconcept{contiguous_iterator}.
1928119292
\item \tcode{End} models \tcode{\libconcept{sized_sentinel_for}<It>}.
1928219293
\end{itemize}
1928319294

19295+
\pnum
19296+
\hardexpects
19297+
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19298+
then \tcode{(last - first) == extent} is \tcode{true}.
19299+
1928419300
\pnum
1928519301
\effects
1928619302
Initializes \exposid{data_} with \tcode{to_address(first)} and
@@ -19351,14 +19367,17 @@
1935119367
\pnum
1935219368
\expects
1935319369
\begin{itemize}
19354-
\item If \tcode{extent} is not equal to \tcode{dynamic_extent},
19355-
then \tcode{ranges::size(r)} is equal to \tcode{extent}.
1935619370
\item \tcode{R} models \tcode{ranges::\libconcept{contiguous_range}} and
1935719371
\tcode{ranges::\libconcept{sized_range}}.
1935819372
\item If \tcode{is_const_v<element_type>} is \tcode{false},
1935919373
\tcode{R} models \tcode{ranges::\libconcept{borrowed_range}}.
1936019374
\end{itemize}
1936119375

19376+
\pnum
19377+
\hardexpects
19378+
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19379+
then \tcode{ranges::size(r) == extent} is \tcode{true}.
19380+
1936219381
\pnum
1936319382
\effects
1936419383
Initializes \exposid{data_} with \tcode{ranges::data(r)} and
@@ -19380,9 +19399,9 @@
1938019399
\tcode{is_const_v<element_type>} is \tcode{true}.
1938119400

1938219401
\pnum
19383-
\expects
19384-
If \tcode{extent} is not equal to \tcode{dynamic_extent}, then
19385-
\tcode{il.size()} is equal to \tcode{extent}.
19402+
\hardexpects
19403+
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19404+
then \tcode{il.size() == extent} is \tcode{true}.
1938619405

1938719406
\pnum
1938819407
\effects
@@ -19420,9 +19439,9 @@
1942019439
\end{itemize}
1942119440

1942219441
\pnum
19423-
\expects
19442+
\hardexpects
1942419443
If \tcode{extent} is not equal to \tcode{dynamic_extent},
19425-
then \tcode{s.size()} is equal to \tcode{extent}.
19444+
then \tcode{s.size() == extent} is \tcode{true}.
1942619445

1942719446
\pnum
1942819447
\effects
@@ -19492,7 +19511,7 @@
1949219511
\tcode{Count <= Extent} is \tcode{true}.
1949319512

1949419513
\pnum
19495-
\expects
19514+
\hardexpects
1949619515
\tcode{Count <= size()} is \tcode{true}.
1949719516

1949819517
\pnum
@@ -19512,7 +19531,7 @@
1951219531
\tcode{Count <= Extent} is \tcode{true}.
1951319532

1951419533
\pnum
19515-
\expects
19534+
\hardexpects
1951619535
\tcode{Count <= size()} is \tcode{true}.
1951719536

1951819537
\pnum
@@ -19536,7 +19555,7 @@
1953619555
is \tcode{true}.
1953719556

1953819557
\pnum
19539-
\expects
19558+
\hardexpects
1954019559
\begin{codeblock}
1954119560
Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset)
1954219561
\end{codeblock}
@@ -19567,7 +19586,7 @@
1956719586

1956819587
\begin{itemdescr}
1956919588
\pnum
19570-
\expects
19589+
\hardexpects
1957119590
\tcode{count <= size()} is \tcode{true}.
1957219591

1957319592
\pnum
@@ -19582,7 +19601,7 @@
1958219601

1958319602
\begin{itemdescr}
1958419603
\pnum
19585-
\expects
19604+
\hardexpects
1958619605
\tcode{count <= size()} is \tcode{true}.
1958719606

1958819607
\pnum
@@ -19598,7 +19617,7 @@
1959819617

1959919618
\begin{itemdescr}
1960019619
\pnum
19601-
\expects
19620+
\hardexpects
1960219621
\begin{codeblock}
1960319622
offset <= size() && (count == dynamic_extent || count <= size() - offset)
1960419623
\end{codeblock}
@@ -19656,7 +19675,7 @@
1965619675

1965719676
\begin{itemdescr}
1965819677
\pnum
19659-
\expects
19678+
\hardexpects
1966019679
\tcode{idx < size()} is \tcode{true}.
1966119680

1966219681
\pnum
@@ -19690,7 +19709,7 @@
1969019709

1969119710
\begin{itemdescr}
1969219711
\pnum
19693-
\expects
19712+
\hardexpects
1969419713
\tcode{empty()} is \tcode{false}.
1969519714

1969619715
\pnum
@@ -19709,7 +19728,7 @@
1970919728

1971019729
\begin{itemdescr}
1971119730
\pnum
19712-
\expects
19731+
\hardexpects
1971319732
\tcode{empty()} is \tcode{false}.
1971419733

1971519734
\pnum
@@ -23876,17 +23895,16 @@
2387623895

2387723896
\pnum
2387823897
\expects
23879-
\begin{itemize}
23880-
\item
23881-
For each rank index \tcode{r} of \tcode{extents_type},
23882-
\tcode{static_extent(r) == dynamic_extent || static_extent(r) == other.extent(r)}
23883-
is \tcode{true}.
23884-
\item
2388523898
$[0, \tcode{\exposid{map_}.required_span_size()})$ is
2388623899
an accessible range of \exposid{ptr_} and \exposid{acc_}
2388723900
for values of \exposid{ptr_}, \exposid{map_}, and \exposid{acc_}
2388823901
after the invocation of this constructor.
23889-
\end{itemize}
23902+
23903+
\pnum
23904+
\hardexpects
23905+
For each rank index \tcode{r} of \tcode{extents_type},
23906+
\tcode{static_extent(r) == dynamic_extent || static_extent(r) == other.extent(r)}
23907+
is \tcode{true}.
2389023908

2389123909
\pnum
2389223910
\effects
@@ -23932,7 +23950,7 @@
2393223950
Let \tcode{I} be \tcode{extents_type::\exposid{index-cast}(std::move(indices))}.
2393323951

2393423952
\pnum
23935-
\expects
23953+
\hardexpects
2393623954
\tcode{I} is a multidimensional index in \tcode{extents()}.
2393723955
\begin{note}
2393823956
This implies that

source/intro.tex

+11-1
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,8 @@
833833
\indextext{conformance requirements!library|)}
834834

835835
\pnum
836-
Two kinds of implementations are defined: a \defnadj{hosted}{implementation} and a
836+
An implementation is either a
837+
\defnadj{hosted}{implementation} or a
837838
\defnadj{freestanding}{implementation}.
838839
A freestanding
839840
implementation is one in which execution may take place without the benefit of
@@ -845,6 +846,15 @@
845846
described in \ref{lex} through \ref{\lastcorechapter} and
846847
the subset of the library facilities described in \ref{compliance}.
847848

849+
\pnum
850+
It is
851+
\impldef{whether the implementation is a hardened implementation}
852+
whether the implementation is a
853+
\defnadj{hardened}{implementation}.
854+
If it is a hardened implementation,
855+
violating a hardened precondition
856+
results in a contract violation\iref{structure.specifications}.
857+
848858
\pnum
849859
An implementation is encouraged to document its limitations in
850860
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,15 +370,33 @@
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
\begin{example}
377376
An implementation can express some such conditions
378377
via the use of a contract assertion,
379378
such as a precondition assertion\iref{dcl.contract.func}.
380379
\end{example}
381380

381+
\item
382+
\hardexpects
383+
conditions that the function assumes to hold whenever it is called.
384+
\begin{itemize}
385+
\item
386+
When invoking the function in a hardened implementation,
387+
prior to any other observable side effects of the function,
388+
one or more contract assertions
389+
whose predicates are as described in the hardened precondition
390+
are evaluated with a checking semantic\iref{basic.contract.eval}.
391+
If any of these assertions is evaluated with a non-terminating semantic
392+
and the contract-violation handler returns,
393+
the program has undefined behavior.
394+
\item
395+
When invoking the function in a non-hardened implementation,
396+
if any hardened precondition is violated,
397+
the program has undefined behavior.
398+
\end{itemize}
399+
382400
\item
383401
\effects
384402
the actions performed by the function.
@@ -434,9 +452,18 @@
434452
If \tcode{F}'s semantics specifies any \Fundescx{Constraints} or \Fundescx{Mandates} elements,
435453
then those requirements are logically imposed prior to the \term{equivalent-to} semantics.
436454
Next, the semantics of the code sequence are determined by the
437-
\Fundescx{Constraints}, \Fundescx{Mandates}, \Fundescx{Preconditions}, \Fundescx{Effects},
438-
\Fundescx{Synchronization}, \Fundescx{Postconditions}, \Fundescx{Returns}, \Fundescx{Throws},
439-
\Fundescx{Complexity}, \Fundescx{Remarks}, and \Fundescx{Error conditions}
455+
\Fundescx{Constraints},
456+
\Fundescx{Mandates},
457+
\Fundescx{Preconditions},
458+
\Fundescx{Hardened preconditions},
459+
\Fundescx{Effects},
460+
\Fundescx{Synchronization},
461+
\Fundescx{Postconditions},
462+
\Fundescx{Returns},
463+
\Fundescx{Throws},
464+
\Fundescx{Complexity},
465+
\Fundescx{Remarks}, and
466+
\Fundescx{Error conditions}
440467
specified for the function invocations contained in the code sequence.
441468
The value returned from \tcode{F} is specified by \tcode{F}'s \Fundescx{Returns} element,
442469
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
@@ -7581,7 +7581,7 @@
75817581

75827582
\begin{itemdescr}
75837583
\pnum
7584-
\expects
7584+
\hardexpects
75857585
\tcode{n < size()} is \tcode{true}.
75867586

75877587
\pnum

0 commit comments

Comments
 (0)