Skip to content

Commit a470da8

Browse files
notadragontkoeppe
authored andcommitted
P2900R14 Contracts for C++
1 parent 458b16a commit a470da8

16 files changed

+1876
-272
lines changed

source/basic.tex

Lines changed: 548 additions & 38 deletions
Large diffs are not rendered by default.

source/classes.tex

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@
475475

476476
\begin{bnf}
477477
\nontermdef{member-declarator}\br
478-
declarator \opt{virt-specifier-seq} \opt{pure-specifier}\br
479-
declarator requires-clause\br
478+
declarator \opt{virt-specifier-seq} \opt{function-contract-specifier-seq} \opt{pure-specifier}\br
479+
declarator requires-clause \opt{function-contract-specifier-seq}\br
480480
declarator brace-or-equal-initializer\br
481481
\opt{identifier} \opt{attribute-specifier-seq} \terminal{:} constant-expression \opt{brace-or-equal-initializer}
482482
\end{bnf}
@@ -527,6 +527,12 @@
527527
the program is ill-formed; see~\ref{temp.spec.general}.
528528
\end{note}
529529

530+
\pnum
531+
The optional \grammarterm{function-contract-specifier-seq}\iref{dcl.contract.func})
532+
in a \grammarterm{member-declarator}
533+
shall be present only if
534+
the \grammarterm{declarator} declares a function.
535+
530536
\pnum
531537
\indextext{definition!class}%
532538
The \grammarterm{member-specification} in a class definition declares the
@@ -618,7 +624,8 @@
618624
\item function body\iref{dcl.fct.def.general},
619625
\item default argument\iref{dcl.fct.default},
620626
\item default template argument\iref{temp.param},
621-
\item \grammarterm{noexcept-specifier}\iref{except.spec}, or
627+
\item \grammarterm{noexcept-specifier}\iref{except.spec},
628+
\item \grammarterm{function-contract-specifier}\iref{dcl.contract.func}, or
622629
\item default member initializer
623630
\end{itemize}
624631
within the \grammarterm{member-specification} of the class or class template.
@@ -4289,17 +4296,17 @@
42894296
\begin{codeblock}
42904297
class A {
42914298
typedef int I; // private member
4292-
I f();
4293-
friend I g(I);
4299+
I f() pre(A::x > 0);
4300+
friend I g(I) post(A::x <= 0);
42944301
static I x;
42954302
template<int> struct Q;
42964303
template<int> friend struct R;
42974304
protected:
42984305
struct B { };
42994306
};
43004307

4301-
A::I A::f() { return 0; }
4302-
A::I g(A::I p = A::x);
4308+
A::I A::f() pre(A::x > 0) { return 0; }
4309+
A::I g(A::I p = A::x) post(A::x <= 0);
43034310
A::I g(A::I p) { return 0; }
43044311
A::I A::x = 0;
43054312
template<A::I> struct A::Q { };
@@ -5720,13 +5727,22 @@
57205727
\tcode{typeid}
57215728
operator\iref{expr.typeid} or of a
57225729
\keyword{dynamic_cast}\iref{expr.dynamic.cast}.
5723-
However, if these operations are performed in a
5724-
\grammarterm{ctor-initializer}
5730+
However, if these operations are performed
5731+
during evaluation of
5732+
\begin{itemize}
5733+
\item
5734+
a \grammarterm{ctor-initializer}
57255735
(or in a function called directly or indirectly from a
57265736
\grammarterm{ctor-initializer})
57275737
before all the
57285738
\grammarterm{mem-initializer}{s}
5729-
for base classes have completed, the program has undefined behavior.
5739+
for base classes have completed,
5740+
\item
5741+
a precondition assertion of a constructor, or
5742+
\item
5743+
a postcondition assertion of a destructor\iref{dcl.contract.func},
5744+
\end{itemize}
5745+
the program has undefined behavior.
57305746
\begin{example}
57315747
\begin{codeblock}
57325748
class A {
@@ -6049,6 +6065,9 @@
60496065
or from a destructor,
60506066
including during the construction or destruction of the class's non-static data
60516067
members,
6068+
or during the evaluation of
6069+
a postcondition assertion of a constructor or
6070+
a precondition assertion of a destructor\iref{dcl.contract.func},
60526071
and the object to which the call applies is the object (call it \tcode{x}) under construction or
60536072
destruction,
60546073
the function called is the

source/compatibility.tex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111
ISO \CppXXIII{},
1212
by the chapters of this document.
1313

14+
\rSec2[diff.cpp23.lex]{\ref{lex}: Lexical conventions}
15+
\diffref{lex.key}
16+
\change
17+
New keywords.
18+
\rationale
19+
Required for new features.
20+
\begin{itemize}
21+
\item
22+
The \keyword{contract_assert} keyword
23+
is added to introduce a contract assertion
24+
through an \grammarterm{assertion-statement}\iref{stmt.contract.assert}.
25+
\end{itemize}
26+
\effect
27+
Valid \CppXXIII{} code using \keyword{contract_assert} as an identifier
28+
is not valid in this revision of \Cpp{}.
29+
1430
\rSec2[diff.cpp23.expr]{\ref{expr}: expressions}
1531

1632
\diffref{expr.arith.conv}
@@ -182,6 +198,7 @@
182198
New functionality.
183199
\effect
184200
The following \Cpp{} headers are new:
201+
\libheaderrefx{contracts}{support.contract},
185202
\libheaderref{debugging},
186203
\libheaderrefx{hazard_pointer}{hazard.pointer.syn},
187204
\libheaderrefx{inplace_vector}{inplace.vector.syn},

0 commit comments

Comments
 (0)