Skip to content

[[nodiscard]] advice is largely absent #2109

Open
@seppeon

Description

@seppeon

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]]"

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