Skip to content

Commit 7d73347

Browse files
JordanMaplesColin Robertson
andauthored
Add documentation for warning C26457 (#3421)
* add documentation for C26457 * update warning page and add entry to table of contents. * Update c26457.md * Delete unneeded metadata Co-authored-by: Colin Robertson <[email protected]>
1 parent 3c3156d commit 7d73347

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

docs/code-quality/c26457.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
description: "Learn more about: C26457 USE_STD_IGNORE_INSTEAD_OF_VOID_CAST"
3+
title: C26457
4+
ms.date: 3/1/2021
5+
f1_keywords: ["C26457"]
6+
helpviewer_keywords: ["C26457"]
7+
---
8+
# C26457 USE_STD_IGNORE_INSTEAD_OF_VOID_CAST
9+
10+
Excerpt from the [C++ Core Guideline for this warning](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es48-avoid-casts):
11+
12+
> Never cast to `(void)` to ignore a `[[nodiscard]]` return value. If you deliberately want to discard such a result, first think hard about whether that is really a good idea (there is usually a good reason the author of the function or of the return type used `[[nodiscard]]` in the first place). If you still think it's appropriate and your code reviewer agrees, use `std::ignore =` to turn off the warning which is simple, portable, and easy to grep.
13+
14+
```C++
15+
struct S{};
16+
[[nodiscard]] S getS();
17+
18+
void function() {
19+
(void) getS(); // C26457
20+
std::ignore = getS(); // OK
21+
}
22+
```

docs/code-quality/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@
137137
href: ../code-quality/c26455.md
138138
- name: C26456
139139
href: ../code-quality/c26456.md
140+
- name: C26457
141+
href: ../code-quality/c26457.md
140142
- name: C26460
141143
href: ../code-quality/c26460.md
142144
- name: C26461

0 commit comments

Comments
 (0)