Repository navigation
Fix non-const shared_ptr callback deprecation warnings with GCC - #3450
christophebedard wants to merge 1 commit into
Conversation
ABI Compliance Check✅ Verdict: compatible (additions only)
✅
|
Subscription callbacks taking a `std::shared_ptr` to a non-const message were deprecated in #2975 (Lyrical), but the `[[deprecated]]` function, `AnySubscriptionCallback::set_deprecated()`, is only used inside rclcpp headers. Downstream packages include these as system headers, and GCC does not show warnings located in system headers, even if user code triggered the template instantiation, so only Clang >= 18 shows the warning. Instead, add `[[deprecated]]` overloads of `create_subscription()` and `create_generic_subscription()` (free functions and `Node` and `LifecycleNode` member functions), constrained to the deprecated callback signatures, so that the warning is located at the user's call. Move the `create_generic_subscription()` implementation to `rclcpp::detail` so that both overloads can use it, like `create_subscription()`. Then remove `set_deprecated()` and the `RCLCPP_AVOID_DEPRECATIONS_FOR_UNIT_TESTS` macro. Since GCC users will only see the warning starting with Makoa, add TODOs to remove these overloads and the support for these callback signatures after Makoa. Also update the `rclcpp_action` tests that used a deprecated callback. Part of #3176 Signed-off-by: Christophe Bedard <[email protected]>
3fe4dbd to
8bf189c
Compare
mini-1235
left a comment
There was a problem hiding this comment.
I did some tests and this works for me! My only concern is that it adds quite a few lines of code, but I am not sure how to better handle the GCC situation, and this will eventually be removed anyway.
|
Pulls: #3450 |
Description
Subscription callbacks taking a
std::shared_ptrto a non-const message were deprecated in #2975 (Lyrical), but the[[deprecated]]function,AnySubscriptionCallback::set_deprecated(), is only used inside rclcpp headers. Downstream packages include these as system headers, and GCC does not show warnings located in system headers, even if user code triggered the template instantiation, so only Clang >= 18 shows the warning.Instead, add
[[deprecated]]overloads ofcreate_subscription()andcreate_generic_subscription()(free functions andNodeandLifecycleNodemember functions), constrained to the deprecated callback signatures, so that the warning is located at the user's call. Then removeset_deprecated()and theRCLCPP_AVOID_DEPRECATIONS_FOR_UNIT_TESTSmacro.Since GCC users will only see the warning starting with Makoa, add TODOs to remove these overloads and the support for these callback signatures after Makoa.
Part of #3176
Is this user-facing behavior change?
Yes: with GCC, subscription callbacks taking a
std::shared_ptr<MessageT>(e.g.,MessageT::SharedPtr) now trigger a deprecation warning at thecreate_subscription()orcreate_generic_subscription()call. Usestd::shared_ptr<const MessageT>(e.g.,MessageT::ConstSharedPtr) instead. With Clang, the warning is now also located at that call, but it is shown twice for theNodeandLifecycleNodemember functions (once for the function template and once for its specialization).Example with GCC 15
Calling
AnySubscriptionCallback::set()directly with a deprecated callback no longer triggers a warning (it previously did only with Clang).Did you use Generative AI?
Claude Opus 5.5 to find out why the warning was not shown with GCC and to implement this fix.
Additional Information
This came up in #3449, which removes these callbacks and should now wait until after Makoa. With this, GCC shows the warning in ros-tooling/topic_tools, which ros-tooling/topic_tools#159 fixes.