ros-controls / realtime_tools

Contains a set of tools that can be used from a hard realtime thread, without breaking the realtime behavior.
https://control.ros.org
BSD 3-Clause "New" or "Revised" License
140 stars 76 forks source link

Add the same compile flags as with ros2_controllers and fix errors #185

Closed christophfroehlich closed 3 weeks ago

christophfroehlich commented 3 weeks ago

Similar to https://github.com/ros-controls/ros2_controllers/pull/961

@firesurfer as we don't have c++20 on humble, we get an error with the designated initializers. And I'm not sure about the line

std::optional<DefaultConstructable> rt_data_access = box;

which gave the error

/workspaces/ros2_rolling_ws/src/realtime_tools/test/realtime_box_best_effort_tests.cpp:133:56: error: choosing ‘constexpr std::optional<_Tp>::optional(_Up&&) [with _Up = realtime_tools::RealtimeBoxBestEffort<DefaultConstructable>&; typename std::enable_if<__and_v<std::__not_<std::is_same<std::optional<_Tp>, typename std::remove_cv<typename std::remove_reference<_Tuple>::type>::type> >, std::__not_<std::is_same<std::in_place_t, typename std::remove_cv<typename std::remove_reference<_Tuple>::type>::type> >, std::is_constructible<_T1, _U1>, std::is_convertible<_U1, _T1> >, bool>::type <anonymous> = true; _Tp = DefaultConstructable]’ over ‘realtime_tools::RealtimeBoxBestEffort<T, mutex_type>::operator std::optional<_Tp>() const [with U = DefaultConstructable; <template-parameter-2-2> = void; T = DefaultConstructable; mutex_type = std::mutex]’ [-Werror=conversion]
  133 |   std::optional<DefaultConstructable> rt_data_access = box;
      |                                                        ^~~
/workspaces/ros2_rolling_ws/src/realtime_tools/test/realtime_box_best_effort_tests.cpp:133:56: error:   for conversion from ‘realtime_tools::RealtimeBoxBestEffort<DefaultConstructable>’ to ‘std::optional<DefaultConstructable>’ [-Werror=conversion]
/workspaces/ros2_rolling_ws/src/realtime_tools/test/realtime_box_best_effort_tests.cpp:133:56: note:   because conversion sequence for the argument is better
cc1plus: some warnings being treated as errors

Could be fixed with

std::optional<DefaultConstructable> rt_data_access = box.tryGet();

or

std::optional<DefaultConstructable> rt_data_access = static_cast<std::optional<DefaultConstructable>>(box);

or maybe with adapting the std::optional<U>> tryGet()operator overload?

codecov-commenter commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 72.13%. Comparing base (2a67d35) to head (3ec20d0).

Files with missing lines Patch % Lines
src/realtime_helpers.cpp 0.00% 5 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #185 +/- ## ========================================== - Coverage 72.29% 72.13% -0.17% ========================================== Files 8 8 Lines 379 384 +5 Branches 63 64 +1 ========================================== + Hits 274 277 +3 - Misses 68 69 +1 - Partials 37 38 +1 ``` | [Flag](https://app.codecov.io/gh/ros-controls/realtime_tools/pull/185/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/ros-controls/realtime_tools/pull/185/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls) | `72.13% <0.00%> (-0.17%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files with missing lines](https://app.codecov.io/gh/ros-controls/realtime_tools/pull/185?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls) | Coverage Δ | | |---|---|---| | [src/realtime\_helpers.cpp](https://app.codecov.io/gh/ros-controls/realtime_tools/pull/185?src=pr&el=tree&filepath=src%2Frealtime_helpers.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-c3JjL3JlYWx0aW1lX2hlbHBlcnMuY3Bw) | `26.76% <0.00%> (ø)` | | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/ros-controls/realtime_tools/pull/185/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls)