Skip to content

Handle ignored [[nodiscard]] set_value() results - #2811

Open
OceanicKr wants to merge 1 commit into
ros-controls:masterfrom
OceanicKr:fix/2808-nodiscard-set-value
Open

OceanicKr wants to merge 1 commit into
ros-controls:masterfrom
OceanicKr:fix/2808-nodiscard-set-value

Conversation

@OceanicKr

Copy link
Copy Markdown

Description

Handles the ignored results of [[nodiscard]] bool set_value(...) reported by -Wunused-result in #2808, in all locations listed there. Each call site follows a pattern already used in this repo:

Call site Handling Existing precedent
on_export_*_interfaces_list() on a freshly created interface std::ignore = ... admittance_controller, chained_filter_controller
Lifecycle resets to NaN / initial setpoints in on_activate() (omni_wheel reset_buffers(), pid on_activate()) if (!...) RCLCPP_WARN(...) DiffDriveController::reset_buffers()
update_reference_from_subscribers() / update_and_write_commands() accumulate with &= (no short-circuit, every interface still gets written), one RCLCPP_WARN_THROTTLE (1 s) set_command_result &= in DiffDriveController::update_and_write_commands()
Tests ASSERT_TRUE(...->set_value(...)) test_omni_wheel_drive_controller.cpp

Packages: diff_drive_controller, force_torque_sensor_broadcaster, imu_sensor_broadcaster, mecanum_drive_controller, omni_wheel_drive_controller, pid_controller.

Fixes #2808

Is this user-facing behavior change?

No functional change. A failed set_value that was previously dropped silently now logs a warning (throttled in update paths).

Did you use Generative AI?

Yes, Claude Opus 5.5 (Claude Code) wrote the patch and helped with this description . I reviewed the changes and ran the build and tests below myself.

Additional Information

Verified in a ros:rolling container against master (b8619af), with clang++ and -DCMAKE_CXX_FLAGS=-Werror=unused-result:

  • Before: build fails, e.g. pid_controller.cpp: 10 errors: ignoring return value of function declared with 'nodiscard' attribute
  • After: all 6 packages build; colcon test: 192 tests, 0 errors, 0 failures, 0 skipped
  • pre-commit (clang-format, codespell, whitespace hooks) passes; cpplint shows no new findings. GCC is left to CI.

Note: #2810 touches the same update_reference_from_subscribers() code in diff_drive_controller and omni_wheel_drive_controller; whichever lands second needs a small rebase.

Fixes -Wunused-result warnings reported in ros-controls#2808.

- Export of freshly created interfaces: explicitly discard with std::ignore
- Lifecycle resets / initial setpoints: RCLCPP_WARN on failure
  (as in DiffDriveController::reset_buffers())
- update() paths: accumulate result and RCLCPP_WARN_THROTTLE once
- Tests: ASSERT_TRUE on set_value()

Fixes ros-controls#2808
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ignored [[nodiscard]] set_value() results (-Wunused-result with clang)

1 participant