Skip to content

Commit 1bef7c5

Browse files
committed
p2900r14 - Contracts for C++
1 parent 8196161 commit 1bef7c5

16 files changed

+1871
-270
lines changed

source/basic.tex

Lines changed: 546 additions & 36 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-spceifier-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.
@@ -4278,17 +4285,17 @@
42784285
\begin{codeblock}
42794286
class A {
42804287
typedef int I; // private member
4281-
I f();
4282-
friend I g(I);
4288+
I f() pre(A::x > 0);
4289+
friend I g(I) post(A::x <= 0);
42834290
static I x;
42844291
template<int> struct Q;
42854292
template<int> friend struct R;
42864293
protected:
42874294
struct B { };
42884295
};
42894296

4290-
A::I A::f() { return 0; }
4291-
A::I g(A::I p = A::x);
4297+
A::I A::f() pre(A::x > 0) { return 0; }
4298+
A::I g(A::I p = A::x) post(A::x <= 0);
42924299
A::I g(A::I p) { return 0; }
42934300
A::I A::x = 0;
42944301
template<A::I> struct A::Q { };
@@ -5709,13 +5716,22 @@
57095716
\tcode{typeid}
57105717
operator\iref{expr.typeid} or of a
57115718
\keyword{dynamic_cast}\iref{expr.dynamic.cast}.
5712-
However, if these operations are performed in a
5713-
\grammarterm{ctor-initializer}
5719+
However, if these operations are performed
5720+
during evaluation of
5721+
\begin{itemize}
5722+
\item
5723+
a \grammarterm{ctor-initializer}
57145724
(or in a function called directly or indirectly from a
57155725
\grammarterm{ctor-initializer})
57165726
before all the
57175727
\grammarterm{mem-initializer}{s}
5718-
for base classes have completed, the program has undefined behavior.
5728+
for base classes have completed,
5729+
\item
5730+
a precondition assertion of a constructor, or
5731+
\item
5732+
a postcondition assertion of a destructor\iref{dcl.contract.func},
5733+
\end{itemize}
5734+
the program has undefined behavior.
57195735
\begin{example}
57205736
\begin{codeblock}
57215737
class A {
@@ -6038,6 +6054,9 @@
60386054
or from a destructor,
60396055
including during the construction or destruction of the class's non-static data
60406056
members,
6057+
or during the evaluation of
6058+
a postcondition assertion of a constructor or
6059+
a precondition assertion of a destructor\iref{dcl.contract.func},
60416060
and the object to which the call applies is the object (call it \tcode{x}) under construction or
60426061
destruction,
60436062
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)