Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
t3nsor opened this issue Oct 24, 2024 · 1 comment

Comments

@t3nsor
Copy link

t3nsor commented Oct 24, 2024

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

@jensmaurer
Copy link
Member

CWG2943

@jensmaurer jensmaurer changed the title [dcl.attr.nodiscard] Discarding call to nodiscard function with void return type CWG2943 [dcl.attr.nodiscard] Discarding call to nodiscard function with void return type Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants