Skip to content

CWG2943 [dcl.attr.nodiscard] Discarding call to nodiscard function with void return type #628

Closed
cplusplus/draft
#7647
@t3nsor

Description

@t3nsor

Full name of submitter: Brian Bi

Reference (section label): [dcl.attr.nodiscard]

Issue description: According to the current wording, a call to a [[nodiscard]] function with void return type is still considered a nodiscard call and the recommended practice is to issue a warning unless the call is explicitly cast to void. Casting to void is pointless in that case and no implementation encourages it. This may arise in the case of function templates with dependent return type.

Suggested resolution: Edit [dcl.attr.nodiscard]/4:

Recommended practice: Appearance of a nodiscard call as a potentially-evaluated discarded-value expression ([expr.prop]) of non-void type is discouraged unless explicitly cast to void. Implementations should issue a warning in such cases. [...]

Note: We don't need to say cv void, because there are no expressions of qualified void type. https://eel.is/c++draft/expr.type#2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions