Skip to content

Commit eddf2c5

Browse files
authored
Merge 2019-07 CWG Motion 7
P1301R4 [[nodiscard("should have a reason")]] Fixes #2986.
2 parents df6ff5c + d6a2917 commit eddf2c5

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

source/declarations.tex

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9025,9 +9025,9 @@
90259025
unsafe. \end{note} It shall appear at most once in each \grammarterm{attribute-list}. An
90269026
\grammarterm{attribute-argument-clause} may be present and, if present, it shall have the form:
90279027

9028-
\begin{codeblock}
9029-
( @\grammarterm{string-literal}@ )
9030-
\end{codeblock}
9028+
\begin{ncbnf}
9029+
\terminal{(} string-literal \terminal{)}
9030+
\end{ncbnf}
90319031
\begin{note} The \grammarterm{string-literal} in the \grammarterm{attribute-argument-clause}
90329032
could be used to explain the rationale for deprecation and/or to suggest a replacing entity.
90339033
\end{note}
@@ -9235,8 +9235,29 @@
92359235
The \grammarterm{attribute-token} \tcode{nodiscard}
92369236
may be applied to the \grammarterm{declarator-id}
92379237
in a function declaration or to the declaration of a class or enumeration.
9238-
It shall appear at most once in each \grammarterm{attribute-list} and
9239-
no \grammarterm{attribute-argument-clause} shall be present.
9238+
It shall appear at most once in each \grammarterm{attribute-list}.
9239+
An \grammarterm{attribute-argument-clause} may be present
9240+
and, if present, it shall have the form:
9241+
9242+
\begin{ncbnf}
9243+
\terminal{(} string-literal \terminal{)}
9244+
\end{ncbnf}
9245+
9246+
\pnum
9247+
A name or entity declared without the \tcode{nodiscard} attribute
9248+
can later be redeclared with the attribute and vice-versa.
9249+
\begin{note}
9250+
Thus, an entity initially declared without the attribute
9251+
can be marked as \tcode{nodiscard}
9252+
by a subsequent redeclaration.
9253+
However, after an entity is marked as \tcode{nodiscard},
9254+
later redeclarations do not remove the \tcode{nodiscard}
9255+
from the entity.
9256+
\end{note}
9257+
Redeclarations using different forms of the attribute
9258+
(with or without the \grammarterm{attribute-argument-clause}
9259+
or with different \grammarterm{attribute-argument-clause}s)
9260+
are allowed.
92409261

92419262
\pnum
92429263
\begin{note}
@@ -9249,6 +9270,10 @@
92499270
Implementations should issue a warning in such cases.
92509271
This is typically because discarding the return value
92519272
of a nodiscard call has surprising consequences.
9273+
The \grammarterm{string-literal}
9274+
in a \tcode{nodiscard} \grammarterm{attribute-argument-clause}
9275+
is intended to be used in the message of the warning
9276+
as the rationale for why the result should not be discarded.
92529277
\end{note}
92539278

92549279
\pnum

source/preprocessor.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
\tcode{likely} & \tcode{201803L} \\
309309
\tcode{maybe_unused} & \tcode{201603L} \\
310310
\tcode{no_unique_address} & \tcode{201803L} \\
311-
\tcode{nodiscard} & \tcode{201603L} \\
311+
\tcode{nodiscard} & \tcode{201907L} \\
312312
\tcode{noreturn} & \tcode{200809L} \\
313313
\tcode{unlikely} & \tcode{201803L} \\
314314
\end{floattable}

0 commit comments

Comments
 (0)