rosidl
rosidl copied to clipboard
Add [[nodiscard]] attribute to C++ headers that return values, such as operators [Jazzy]
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 https://github.com/gazebosim/sdformat/issues/1358
Reviewing from our issue triaging meeting, sounds like a nice improvement, help is appreciated.