Skip to content

Commit 0ddcc1c

Browse files
committed
P1301R4 [[nodiscard("should have a reason")]]
1 parent 67db942 commit 0ddcc1c

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

source/declarations.tex

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

9015-
\begin{codeblock}
9016-
( @\grammarterm{string-literal}@ )
9017-
\end{codeblock}
9015+
\begin{ncbnf}
9016+
\terminal{(} string-literal \terminal{)}
9017+
\end{ncbnf}
90189018
\begin{note} The \grammarterm{string-literal} in the \grammarterm{attribute-argument-clause}
90199019
could be used to explain the rationale for deprecation and/or to suggest a replacing entity.
90209020
\end{note}
@@ -9207,8 +9207,29 @@
92079207
The \grammarterm{attribute-token} \tcode{nodiscard}
92089208
may be applied to the \grammarterm{declarator-id}
92099209
in a function declaration or to the declaration of a class or enumeration.
9210-
It shall appear at most once in each \grammarterm{attribute-list} and
9211-
no \grammarterm{attribute-argument-clause} shall be present.
9210+
It shall appear at most once in each \grammarterm{attribute-list}.
9211+
An \grammarterm{attribute-argument-clause} may be present
9212+
and, if present, it shall have the form:
9213+
9214+
\begin{ncbnf}
9215+
\terminal{(} string-literal \terminal{)}
9216+
\end{ncbnf}
9217+
9218+
\pnum
9219+
A name or entity declared without the \tcode{nodiscard} attribute
9220+
can later be redeclared with the attribute and vice-versa.
9221+
\begin{note}
9222+
Thus, an entity initially declared without the attribute
9223+
can be marked as \tcode{nodiscard}
9224+
by a subsequent redeclaration.
9225+
However, after an entity is marked as \tcode{nodiscard},
9226+
later redeclarations do not remove the \tcode{nodiscard}
9227+
from the entity.
9228+
\end{note}
9229+
Redeclarations using different forms of the attribute
9230+
(with or without the \grammarterm{attribute-argument-clause}
9231+
or with different \grammarterm{attribute-argument-clause}s)
9232+
are allowed.
92129233

92139234
\pnum
92149235
\begin{note}
@@ -9221,6 +9242,12 @@
92219242
Implementations should issue a warning in such cases.
92229243
This is typically because discarding the return value
92239244
of a nodiscard call has surprising consequences.
9245+
The \grammarterm{string-literal}
9246+
in a \tcode{nodiscard} \grammarterm{attribute-argument-clause}
9247+
is intended to be used in the message of the warning
9248+
as the rationale for why the entity must not be discarded
9249+
or to suggest alternative entities
9250+
that may demonstrate the intent or proper usage.
92249251
\end{note}
92259252

92269253
\pnum

source/preprocessor.tex

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

0 commit comments

Comments
 (0)