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

Add [[nodiscard]] attribute to C++ headers that return values, such as operators [Jazzy] #786

Open
Ryanf55 opened this issue Feb 26, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@Ryanf55
Copy link

Ryanf55 commented Feb 26, 2024

Feature request

Feature description

Getters and operators could have the [[nodiscard]] attribute to prevent bugs.

Implementation considerations

See /opt/ros/humble/include/geometry_msgs/geometry_msgs/msg/detail/point__struct.hpp. This is ABI breaking because it increases the strictness of the API.

Before:

  bool operator!=(const Point_ & other) const
  {
    return !this->operator==(other);
  }
  

Proposed:

  [[nodiscard]] bool operator!=(const Point_ & other) const
  {
    return !this->operator==(other);
  }

Effect:

Using the != operator without assigning the value would then issue a compile warning.

Related

Same as gazebosim/sdformat#1358

@wjwwood wjwwood added the help wanted Extra attention is needed label Mar 7, 2024
@wjwwood
Copy link
Member

wjwwood commented Mar 7, 2024

Reviewing from our issue triaging meeting, sounds like a nice improvement, help is appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants