Repository navigation
Remove deprecated non-const shared_ptr subscription callbacks - #3449
christophebedard wants to merge 2 commits into
Conversation
Subscription callbacks taking a `std::shared_ptr` to a non-const message (`MessageT`, the ROS message type of a type adapter, or `rclcpp::SerializedMessage`), with or without `rclcpp::MessageInfo`, have been deprecated since #2975 (Lyrical) in favor of the `std::shared_ptr<const MessageT>` signatures. Remove them, as well as the `RCLCPP_AVOID_DEPRECATIONS_FOR_UNIT_TESTS` macro and the tests for these signatures, and update the `rclcpp_action` tests that still used one. Without the variant alternatives, these callbacks would silently be dispatched as `std::unique_ptr<MessageT>` callbacks, so reject them with a `static_assert` instead. This also covers `const std::shared_ptr<MessageT> &` callbacks, which were previously rejected as ambiguous. Signed-off-by: Christophe Bedard <[email protected]>
ABI Compliance Check❌ Verdict: incompatible
✅
|
|
Pulls: #3449 |
Subscription callbacks taking a `std::shared_ptr` to a non-const message have been deprecated since ros2/rclcpp#2975 (Lyrical), and they are being removed in Rolling by ros2/rclcpp#3449. These callbacks do not modify the message, and `from_input_tensor_msg()` takes a `const` reference. Signed-off-by: Christophe Bedard <[email protected]>
Subscription callbacks taking a `std::shared_ptr` to a non-const message have been deprecated since ros2/rclcpp#2975 (Lyrical), and they are being removed in Rolling by ros2/rclcpp#3449. These callbacks do not modify the message, so take a `ConstSharedPtr`, including in the README examples. The qc tutorial subscriber reads the data through `get_data_ptr()`, which needed a non-const buffer, so add a `const` overload that returns a read-only pointer. Signed-off-by: Christophe Bedard <[email protected]>
#7539) Subscription callbacks taking a `std::shared_ptr` to a non-const message have been deprecated since ros2/rclcpp#2975 (Lyrical), and they are being removed in Rolling by ros2/rclcpp#3449. These callbacks do not modify the message, and `from_input_tensor_msg()` takes a `const` reference. (cherry picked from commit 6c90829) Signed-off-by: Christophe Bedard <[email protected]> Co-authored-by: Christophe Bedard <[email protected]>
jmachowinski
left a comment
There was a problem hiding this comment.
How do the compiler errors look like for this now ? 2 pages of wall of template failue ?
If yes, can we make this nicer now that we got the power of c++20 concepts ?
mini-1235
left a comment
There was a problem hiding this comment.
I think removing the non-const subscription callback type would probably cause a lot of build failures in downstream packages.
A few months ago, I noticed that the deprecation warnings were only showing up sometimes, so I opened an issue here: #3176. I did some investigation afterwards (but forgot to update the issue), and I believe the warnings only show up when compiling with Clang, while GCC does not seem to produce any warnings.
The pattern I observed is that if the [[deprecated]] attribute is not directly applied to the function, GCC doesn't emit a warning. In the case of this PR, we don't put [[deprecated]] directly on create_subscription, so GCC doesn't warn about it.
I don't know much about compiler internals, and haven't had the time to check whether this is expected GCC behavior, so I am not sure what the best solution would be here. But commenting here, as I don't think it is safe to remove the non-const callback type just yet.
Thanks for pointing this out, I hadn't seen that issue. That seems to be correct. Given the nature of what we're trying to deprecate, I think we'll have to push the removal to N-turtle and figure out how to properly warn users about the deprecation in Makoa. Changing to draft for now. #3445 has the same problem. |
Callbacks without parameters, which are invalid anyway, made `argument_type<0>` fail in `std::tuple_element`, adding unrelated errors before the usual `no match for 'operator='` error. Signed-off-by: Christophe Bedard <[email protected]>
not bad? It's a single error with the GCC output (15.2)Clang output (21.1)
It seems like using concepts would require changes to Clang output with a concept |
@mini-1235 I've got a PR for proper deprecation warnings (on both gcc and clang): #3450 |
Description
Subscription callbacks taking a
std::shared_ptrto a non-const message (MessageT, the ROS message type of a type adapter, orrclcpp::SerializedMessage), with or withoutrclcpp::MessageInfo, have been deprecated since #2975 (Lyrical) in favor of thestd::shared_ptr<const MessageT>signatures. Remove them, as well as theRCLCPP_AVOID_DEPRECATIONS_FOR_UNIT_TESTSmacro and the tests for these signatures, and update therclcpp_actiontests that still used one.Without the variant alternatives, these callbacks would silently be dispatched as
std::unique_ptr<MessageT>callbacks, so reject them with astatic_assertinstead. This also coversconst std::shared_ptr<MessageT> &callbacks, which were previously rejected as ambiguous.Is this user-facing behavior change?
Yes: subscription callbacks taking a
std::shared_ptr<MessageT>(e.g.,MessageT::SharedPtr) now fail to compile. Usestd::shared_ptr<const MessageT>(e.g.,MessageT::ConstSharedPtr) instead.Did you use Generative AI?
Claude Opus 5.5 to find this deprecated code and remove it.
Additional Information
Requires ros2/system_tests#620 and ros-tooling/topic_tools#159, which update callbacks that used these signatures, so merge those first.
Companion PR: ros2/ros2_documentation#7532, which updates the buffer backend examples.
Companion PRs: ros2/rosidl_buffer_backends#44 and ros2/rosidl_buffer_backends_tutorials#5, which update subscription callbacks in those repositories.