isocpp / isocpp/CppCoreGuidelines
`[[nodiscard]]` advice is largely absent
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:
- When a stateless function has a non-void return value and no output parameters.
- With functions that return error codes, especially the new
std::expectedand almost alwaysstd::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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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