isocpp / isocpp/CppCoreGuidelines

`[[nodiscard]]` advice is largely absent

Open
#2,109 14 comments 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
45.3k
Forks
5.6k
PR merge metrics
No merged PRs in 30d

Description

I noticed today that [[nodiscard]] isn't present in this set of guidelines (apart from not ignoring results of functions declared nodiscard and not using void casts to ignore). I think there are some clear cases where guidance would help people:

  1. When a stateless function has a non-void return value and no output parameters.
  2. With functions that return error codes, especially the new std::expected and almost always std::optional's.

Some broad guidance may also be useful, such as:

  • "When it doesn't make sense for the caller of a function to discard the result, declare it [[nodiscard]]"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the existing guidance on ignoring nodiscard results and void casts, then read the issue's 14-comment discussion for decisions or objections. Done means adding agreed guidance for stateless non-void functions, error-code returns, std::expected, std::optional, and the proposed broad rule.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.