Skip to content

Commit b3f2432

Browse files
authored
Merge 2018-06 LWG Motion 14
Fixes #2132
2 parents 992feb2 + 9498923 commit b3f2432

File tree

2 files changed

+90
-26
lines changed

2 files changed

+90
-26
lines changed

source/lib-intro.tex

Lines changed: 85 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -495,37 +495,92 @@
495495

496496
\pnum
497497
Descriptions of function semantics contain the following elements (as
498-
appropriate):\footnote{To save space, items that do not apply to a function are omitted.
499-
For example, if a function does not specify any
500-
further
501-
preconditions, there will be no \requires paragraph.}
498+
appropriate):\footnote{To save space, elements that do not apply to a function are omitted.
499+
For example, if a function specifies no
500+
preconditions, there will be no \expects element.}
502501

503502
\begin{itemize}
504-
\item \requires the preconditions for calling the function
505-
\item \effects the actions performed by the function
506-
\item \sync the synchronization operations\iref{intro.multithread} applicable to the function
507-
\item \postconditions the observable results established by the function
508-
\item \returns a description of the value(s) returned by the function
509-
\item \throws any exceptions thrown by the function, and the conditions that would cause the exception
510-
\item \complexity the time and/or space complexity of the function
511-
\item \remarks additional semantic constraints on the function
512-
\item \errors the error conditions for error codes reported by the function
503+
\item
504+
\requires the preconditions for calling the function.
505+
506+
\item
507+
\constraints the conditions for the function's participation
508+
in overload resolution\iref{over.match}.
509+
\begin{note}
510+
Failure to meet such a condition results in the function's silent non-viability.
511+
\end{note}
512+
\begin{example}
513+
An implementation might express such a condition
514+
via a \grammarterm{constraint-expression}\iref{temp.constr.decl}.
515+
\end{example}
516+
517+
\item
518+
\mandates the conditions that, if not met, render the program ill-formed.
519+
\begin{example}
520+
An implementation might express such a condition
521+
via the \grammarterm{constant-expression}
522+
in a \grammarterm{static\_assert-declaration}\iref{dcl.dcl}.
523+
If the diagnostic is to be emitted only after the function
524+
has been selected by overload resolution,
525+
an implementation might express such a condition
526+
via a \grammarterm{constraint-expression}\iref{temp.constr.decl}
527+
and also define the function as deleted.
528+
\end{example}
529+
530+
\item
531+
\expects the conditions (sometimes termed preconditions)
532+
that the function assumes to hold whenever it is called.
533+
\begin{example}
534+
An implementation might express such conditions
535+
via an attribute such as \tcode{[[expects]]}\iref{dcl.attr.contract}.
536+
However, some such conditions might not lend themselves
537+
to expression via code.
538+
\end{example}
539+
540+
\item
541+
\effects the actions performed by the function.
542+
543+
\item
544+
\sync the synchronization operations\iref{intro.multithread} applicable to the function.
545+
546+
\item
547+
\ensures the conditions (sometimes termed observable results or postconditions)
548+
established by the function.
549+
550+
\item
551+
\returns a description of the value(s) returned by the function.
552+
553+
\item
554+
\throws any exceptions thrown by the function, and the conditions that would cause the exception.
555+
556+
\item
557+
\complexity the time and/or space complexity of the function.
558+
559+
\item
560+
\remarks additional semantic constraints on the function.
561+
562+
\item
563+
\errors the error conditions for error codes reported by the function.
513564
\end{itemize}
514565

515566
\pnum
516567
Whenever the \Fundescx{Effects} element specifies that the semantics of some function
517568
\tcode{F} are \term{Equivalent to} some code sequence, then the various elements are
518-
interpreted as follows. If \tcode{F}'s semantics specifies a \Fundescx{Requires} element, then
519-
that requirement is logically imposed prior to the \term{equivalent-to} semantics.
520-
Next, the semantics of the code sequence are determined by the \Fundescx{Requires}, \Fundescx{Effects},
521-
\Fundescx{Synchronization}, \Fundescx{Postconditions}, \Fundescx{Returns}, \Fundescx{Throws}, \Fundescx{Complexity}, \Fundescx{Remarks}, and \Fundescx{Error conditions}
522-
specified for the function invocations contained in the code sequence. The value
523-
returned from \tcode{F} is specified by \tcode{F}'s \Fundescx{Returns} element, or if \tcode{F}
524-
has no \Fundescx{Returns} element, a non-\tcode{void} return from \tcode{F} is specified by the
569+
interpreted as follows.
570+
If \tcode{F}'s semantics specifies any \Fundescx{Constraints} or \Fundescx{Mandates} elements,
571+
then those requirements are logically imposed prior to the \term{equivalent-to} semantics.
572+
Next, the semantics of the code sequence are determined by the
573+
\Fundescx{Constraints}, \Fundescx{Mandates}, \Fundescx{Expects}, \Fundescx{Effects},
574+
\Fundescx{Synchronization}, \Fundescx{Ensures}, \Fundescx{Returns}, \Fundescx{Throws},
575+
\Fundescx{Complexity}, \Fundescx{Remarks}, and \Fundescx{Error conditions}
576+
specified for the function invocations contained in the code sequence.
577+
The value returned from \tcode{F} is specified by \tcode{F}'s \Fundescx{Returns} element,
578+
or if \tcode{F} has no \Fundescx{Returns} element,
579+
a non-\tcode{void} return from \tcode{F} is specified by the
525580
\tcode{return} statements\iref{stmt.return} in the code sequence.
526581
If \tcode{F}'s semantics contains a \Fundescx{Throws},
527-
\Fundescx{Postconditions}, or \Fundescx{Complexity} element, then that supersedes any occurrences of that
528-
element in the code sequence.
582+
\Fundescx{Ensures}, or \Fundescx{Complexity} element,
583+
then that supersedes any occurrences of that element in the code sequence.
529584

530585
\pnum
531586
For non-reserved replacement and handler functions,
@@ -2737,11 +2792,16 @@
27372792

27382793
\pnum
27392794
\indextext{restriction}%
2740-
Violation of the preconditions specified in a function's
2795+
Violation of any preconditions specified in a function's
27412796
\requires
2742-
paragraph results in undefined behavior unless the function's
2797+
element results in undefined behavior unless the function's
27432798
\throws
2744-
paragraph specifies throwing an exception when the precondition is violated.
2799+
element specifies throwing an exception when the precondition is violated.
2800+
2801+
\pnum
2802+
Violation of any preconditions specified
2803+
in a function's \expects element
2804+
results in undefined behavior.
27452805

27462806
\rSec2[conforming]{Conforming implementations}
27472807

source/macros.tex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,12 @@
234234
\newcommand{\Fundesc}[1]{\Fundescx{#1:}\space}
235235
\newcommand{\required}{\Fundesc{Required behavior}}
236236
\newcommand{\requires}{\Fundesc{Requires}}
237+
\newcommand{\constraints}{\Fundesc{Constraints}}
238+
\newcommand{\mandates}{\Fundesc{Mandates}}
239+
\newcommand{\expects}{\Fundesc{Expects}}
237240
\newcommand{\effects}{\Fundesc{Effects}}
238-
\newcommand{\postconditions}{\Fundesc{Postconditions}}
241+
\newcommand{\ensures}{\Fundesc{Ensures}}
242+
\newcommand{\postconditions}{\ensures}
239243
\newcommand{\returns}{\Fundesc{Returns}}
240244
\newcommand{\throws}{\Fundesc{Throws}}
241245
\newcommand{\default}{\Fundesc{Default behavior}}

0 commit comments

Comments
 (0)