Skip to content

Deprecate the shared_ptr<MessageT> subscription callback signatures - #2975

Merged
ahcorde merged 6 commits into
ros2:rollingfrom
mini-1235:feat/static_assert
Dec 26, 2025
Merged

ahcorde merged 6 commits into
ros2:rollingfrom
mini-1235:feat/static_assert

Conversation

@mini-1235

Copy link
Copy Markdown
Contributor

Description

  • Add static assert for removed subscription callback signatures

Fixes #2972

Is this user-facing behavior change?

Yes

Did you use Generative AI?

No

Additional Information

When working on this PR, I noticed that #1713 only deprecates MessageT. However, looking at the comment here:

// Deprecated signatures:
using SharedPtrCallback =
std::function<void (std::shared_ptr<SubscribedType>)>;
using SharedPtrROSMessageCallback =
std::function<void (std::shared_ptr<ROSMessageType>)>;
using SharedPtrWithInfoCallback =
std::function<void (std::shared_ptr<SubscribedType>, const rclcpp::MessageInfo &)>;
using SharedPtrWithInfoROSMessageCallback =
std::function<void (
std::shared_ptr<ROSMessageType>,
const rclcpp::MessageInfo &)>;
using SharedPtrSerializedMessageCallback =
std::function<void (std::shared_ptr<rclcpp::SerializedMessage>)>;
using SharedPtrSerializedMessageWithInfoCallback =
std::function<void (std::shared_ptr<rclcpp::SerializedMessage>, const rclcpp::MessageInfo &)>;

it looks like the type_adaptation/serialized message are not yet deprecated, how should we proceed?

In the meantime, I have also updated the tests for type_adaptation/serialized to use std::shared_ptr<const>

@mini-1235

mini-1235 commented Nov 9, 2025 •

Copy link
Copy Markdown
Contributor Author

I have pulled and built the ROS2 repos from https://raw.githubusercontent.com/ros2/ros2/rolling/ros2.repos (Please let me know if there are any other repos I should include)

Removing std::shared_ptr<MessageT> would have an impact on:

Removing/Deprecating std::shared_ptr<TypeAdapter/Serialize Message> would affect:

@fujitatomoya fujitatomoya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mini-1235 thanks for fixing up all the related packages and repositories.

changing signatures are totally fine things to do including this PR, but i want to discuss with you on either we should enforcement or deprecation here for the next release.

@mini-1235

Copy link
Copy Markdown
Contributor Author

I am not sure how to deal with the deprecated tests here

void shared_ptr_ta_free_func(std::shared_ptr<MyEmpty>) {}
void shared_ptr_ta_w_info_free_func(
std::shared_ptr<MyEmpty>, const rclcpp::MessageInfo &)
{}
INSTANTIATE_TEST_SUITE_P(
SharedPtrCallbackTests,
DispatchTestsWithTA,
::testing::Values(
// lambda
InstanceContext<MyTA>{"lambda_ta", rclcpp::AnySubscriptionCallback<MyTA>().set(
[](std::shared_ptr<MyEmpty>) {})},
InstanceContext<MyTA>{"lambda_ta_with_info",
rclcpp::AnySubscriptionCallback<MyTA>().set(
[](std::shared_ptr<MyEmpty>, const rclcpp::MessageInfo &) {})},
InstanceContext<MyTA>{"lambda", rclcpp::AnySubscriptionCallback<MyTA>().set(
[](std::shared_ptr<test_msgs::msg::Empty>) {})},
InstanceContext<MyTA>{"lambda_with_info",
rclcpp::AnySubscriptionCallback<MyTA>().set(
[](std::shared_ptr<test_msgs::msg::Empty>, const rclcpp::MessageInfo &) {})},
// free function
InstanceContext<MyTA>{"free_function_ta", rclcpp::AnySubscriptionCallback<MyTA>().set(
shared_ptr_ta_free_func)},
InstanceContext<MyTA>{"free_function_ta_with_info",
rclcpp::AnySubscriptionCallback<MyTA>().set(
shared_ptr_ta_w_info_free_func)},
InstanceContext<MyTA>{"free_function", rclcpp::AnySubscriptionCallback<MyTA>().set(
shared_ptr_free_func)},
InstanceContext<MyTA>{"free_function_with_info",
rclcpp::AnySubscriptionCallback<MyTA>().set(
shared_ptr_w_info_free_func)},
// bind function
BindContext<MyTA, std::shared_ptr<MyEmpty>>("bind_method_ta"),
BindContext<MyTA, std::shared_ptr<MyEmpty>, const rclcpp::MessageInfo &>(
"bind_method_ta_with_info"),
BindContext<MyTA, std::shared_ptr<test_msgs::msg::Empty>>("bind_method"),
BindContext<MyTA, std::shared_ptr<test_msgs::msg::Empty>, const rclcpp::MessageInfo &>(
"bind_method_with_info")
),
format_parameter_with_ta
);

Should I add #define RCLCPP_AVOID_DEPRECATIONS_FOR_UNIT_TESTS 1 like the previous PR or any other better approach?

@mini-1235 mini-1235 changed the title Add static assert for removed subscription callback signatures Deprecate the shared_ptr<MessageT> subscription callback signatures Nov 27, 2025
@mjcarroll

Copy link
Copy Markdown
Member

Should I add #define RCLCPP_AVOID_DEPRECATIONS_FOR_UNIT_TESTS 1 like the previous PR or any other better approach?

Please do!

Then we can remove them in the next cycle with find/replace

@mini-1235

Copy link
Copy Markdown
Contributor Author

Should I add #define RCLCPP_AVOID_DEPRECATIONS_FOR_UNIT_TESTS 1 like the previous PR or any other better approach?

Please do!

Then we can remove them in the next cycle with find/replace

Added!

Signed-off-by: mini-1235 <[email protected]>

@fujitatomoya fujitatomoya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with green CI.

@fujitatomoya

Copy link
Copy Markdown
Collaborator

Pulls: #2975
Gist: https://gist.githubusercontent.com/fujitatomoya/76e9ee5ac26e9d10c870d5850669c3aa/raw/6757efc08e3846630a7c8cd8a07f4905bcd864c1/ros2.repos
BUILD args: --packages-above-and-dependencies rclcpp
TEST args: --packages-above rclcpp
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/17705

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@mjcarroll

Copy link
Copy Markdown
Member

@mini-1235 looks like there were some uncrustify issues here. Can you address those?

@mini-1235

Copy link
Copy Markdown
Contributor Author

As reported in uncrustify/uncrustify#4250, this is a known issue in uncrustify 0.78.1. To avoid timeout, I will skip the uncrustify check here

Signed-off-by: mini-1235 <[email protected]>
@fujitatomoya

fujitatomoya commented Dec 20, 2025 •

Copy link
Copy Markdown
Collaborator
  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@ahcorde
ahcorde merged commit c85ff92 into ros2:rolling Dec 26, 2025
@mini-1235
mini-1235 deleted the feat/static_assert branch December 26, 2025 21:43
bartalor pushed a commit to bartalor/rclcpp that referenced this pull request Jul 15, 2026
ahcorde pushed a commit to ros2/ros2_documentation that referenced this pull request Nov 27, 2026
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]>
ahcorde pushed a commit to ros2/rosidl_buffer_backends that referenced this pull request Nov 27, 2026
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]>
ahcorde pushed a commit to ros2/ros2_documentation that referenced this pull request Nov 27, 2026
#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]>
christophebedard added a commit to ros2/system_tests that referenced this pull request Nov 27, 2026
Subscription callbacks taking a `std::shared_ptr` to a non-const
message have been deprecated since
ros2/rclcpp#2975 (Lyrical), and `rclcpp` is
removing them. These callbacks do not modify the message.

Signed-off-by: Christophe Bedard <[email protected]>
christophebedard added a commit that referenced this pull request Nov 28, 2026
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]>
christophebedard added a commit to ros-tooling/topic_tools that referenced this pull request Nov 28, 2026
Subscription callbacks taking a `std::shared_ptr` to a non-const
message have been deprecated since
ros2/rclcpp#2975 (Lyrical), and `rclcpp` is
removing them. `process_message()` does not modify the message, so
take a `std::shared_ptr<const rclcpp::SerializedMessage>` instead.

Signed-off-by: Christophe Bedard <[email protected]>
fujitatomoya pushed a commit that referenced this pull request Nov 29, 2026
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]>
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.

Deprecated subscription callback signatures are still compiling

5 participants