Skip to content

Latest commit

 

History

History
22 lines (18 loc) · 955 Bytes

c26457.md

File metadata and controls

22 lines (18 loc) · 955 Bytes
description title ms.date f1_keywords helpviewer_keywords
Learn more about: C26457 USE_STD_IGNORE_INSTEAD_OF_VOID_CAST
C26457
3/1/2021
C26457
C26457

C26457 USE_STD_IGNORE_INSTEAD_OF_VOID_CAST

Excerpt from the C++ Core Guideline for this warning:

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.

struct S{};
[[nodiscard]] S getS();

void function() {
    (void) getS(); // C26457
    std::ignore = getS(); // OK
}