Skip to content

Commit 21a19db

Browse files
Dawn Perchikzygoloid
authored andcommitted
P1323R2 Contract postconditions and return type deduction
1 parent cad039d commit 21a19db

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

source/declarations.tex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8316,13 +8316,19 @@
83168316
The attribute may be applied to the function type of a function declaration.
83178317
A postcondition may introduce an identifier to represent
83188318
the glvalue result or the prvalue result object of the function.
8319+
When the declared return type of a non-templated function
8320+
contains a placeholder type,
8321+
the optional \grammarterm{identifier} shall only be present in a definition.
83198322
\begin{example}
83208323
\begin{codeblock}
83218324
int f(char * c)
83228325
[[ensures res: res > 0 && c != nullptr]];
83238326

83248327
int g(double * p)
83258328
[[ensures audit res: res != 0 && p != nullptr && *p <= 0.0]];
8329+
8330+
auto h(int x)
8331+
[[ensures res: true]]; // error: cannot name the return value
83268332
\end{codeblock}
83278333
\end{example}
83288334

@@ -8436,7 +8442,10 @@
84368442
\pnum
84378443
The predicate of a contract condition has the same semantic restrictions
84388444
as if it appeared as the first \grammarterm{expression-statement}
8439-
in the body of the function it applies to.
8445+
in the body of the function it applies to,
8446+
except that the return type of the function is
8447+
known in a contract condition appertaining to its definition,
8448+
even if the return type contains a placeholder type.
84408449

84418450
\pnum
84428451
A precondition is checked by evaluating its predicate

source/templates.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5085,6 +5085,11 @@
50855085
\mname{func}\iref{dcl.fct.def.general}, where any enclosing function is a
50865086
template, a member of a class template, or a generic lambda,
50875087

5088+
\item
5089+
the \grammarterm{identifier} introduced in
5090+
a postcondition\iref{dcl.attr.contract} to represent the result of
5091+
a templated function whose declared return type contains a placeholder type,
5092+
50885093
\item
50895094
a
50905095
\grammarterm{template-id}

0 commit comments

Comments
 (0)