tmp/tmpwluj0eu4/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Nodiscard attribute <a id="dcl.attr.nodiscard">[[dcl.attr.nodiscard]]</a>
|
| 2 |
+
|
| 3 |
+
The *attribute-token* `nodiscard` may be applied to the *declarator-id*
|
| 4 |
+
in a function declaration or to the declaration of a class or
|
| 5 |
+
enumeration. It shall appear at most once in each *attribute-list* and
|
| 6 |
+
no *attribute-argument-clause* shall be present.
|
| 7 |
+
|
| 8 |
+
[*Note 1*: A nodiscard call is a function call expression that calls a
|
| 9 |
+
function previously declared `nodiscard`, or whose return type is a
|
| 10 |
+
possibly cv-qualified class or enumeration type marked `nodiscard`.
|
| 11 |
+
Appearance of a nodiscard call as a potentially-evaluated
|
| 12 |
+
discarded-value expression (Clause [[expr]]) is discouraged unless
|
| 13 |
+
explicitly cast to `void`. Implementations are encouraged to issue a
|
| 14 |
+
warning in such cases. This is typically because discarding the return
|
| 15 |
+
value of a nodiscard call has surprising consequences. — *end note*]
|
| 16 |
+
|
| 17 |
+
[*Example 1*:
|
| 18 |
+
|
| 19 |
+
``` cpp
|
| 20 |
+
struct [[nodiscard]] error_info { ... };
|
| 21 |
+
error_info enable_missile_safety_mode();
|
| 22 |
+
void launch_missiles();
|
| 23 |
+
void test_missiles() {
|
| 24 |
+
enable_missile_safety_mode(); // warning encouraged
|
| 25 |
+
launch_missiles();
|
| 26 |
+
}
|
| 27 |
+
error_info &foo();
|
| 28 |
+
void f() { foo(); } // warning not encouraged: not a nodiscard call, because neither
|
| 29 |
+
// the (reference) return type nor the function is declared nodiscard
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
— *end example*]
|
| 33 |
+
|