Skip to content

Remove deprecated non-const shared_ptr subscription callbacks - #3449

Draft
christophebedard wants to merge 2 commits into
rollingfrom
christophebedard/remove-non-const-shared-ptr-callbacks
Draft

christophebedard wants to merge 2 commits into
rollingfrom
christophebedard/remove-non-const-shared-ptr-callbacks

Conversation

@christophebedard

@christophebedard christophebedard commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Description

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.

Is this user-facing behavior change?

Yes: subscription callbacks taking a std::shared_ptr<MessageT> (e.g., MessageT::SharedPtr) now fail to compile. Use std::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.

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]>
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

ABI Compliance Check

❌ Verdict: incompatible

Library Verdict Summary
libcomponent_manager.so ✅ compatible No ABI changes detected.
librclcpp.so ❌ incompatible ABI-incompatible changes detected.
librclcpp_action.so ✅ compatible No ABI changes detected.
librclcpp_lifecycle.so ✅ compatible No ABI changes detected.
✅ libcomponent_manager.so — full abidiff report

Compared:

  • Base: lib-base/libcomponent_manager.so
  • Head: lib-pr/libcomponent_manager.so @ 27a77ae
(empty report — no differences printed by abidiff)
❌ librclcpp.so — full abidiff report

Compared:

  • Base: lib-base/librclcpp.so
  • Head: lib-pr/librclcpp.so @ 27a77ae
Functions changes summary: 4 Removed (172 filtered out), 4 Changed (72 filtered out), 0 Added (118 filtered out) functions
Variables changes summary: 0 Removed (7 filtered out), 0 Changed, 0 Added (7 filtered out) variables

4 Removed functions:

  [D] 'function char* tracetools::get_symbol<void,std::shared_ptr<rclcpp::SerializedMessage>,constrclcpp::MessageInfo&>(std::function<void(std::shared_ptr<rclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>)'    {_ZN10tracetools10get_symbolIvJSt10shared_ptrIN6rclcpp17SerializedMessageEERKNS2_11MessageInfoEEEEPcSt8functionIFT_DpT0_EE}
  [D] 'function char* tracetools::get_symbol<void,std::shared_ptr<rclcpp::SerializedMessage>>(std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)>)'    {_ZN10tracetools10get_symbolIvJSt10shared_ptrIN6rclcpp17SerializedMessageEEEEEPcSt8functionIFT_DpT0_EE}
  [D] 'function char* tracetools::get_symbol<void,std::shared_ptr<rosgraph_msgs::msg::Clock_<std::allocator<void>>>,constrclcpp::MessageInfo&>(std::function<void(std::shared_ptr<rosgraph_msgs::msg::Clock_<std::allocator<void>>>,constrclcpp::MessageInfo&)>)'    {_ZN10tracetools10get_symbolIvJSt10shared_ptrIN13rosgraph_msgs3msg6Clock_ISaIvEEEERKN6rclcpp11MessageInfoEEEEPcSt8functionIFT_DpT0_EE}
  [D] 'function char* tracetools::get_symbol<void,std::shared_ptr<rosgraph_msgs::msg::Clock_<std::allocator<void>>>>(std::function<void(std::shared_ptr<rosgraph_msgs::msg::Clock_<std::allocator<void>>>)>)'    {_ZN10tracetools10get_symbolIvJSt10shared_ptrIN13rosgraph_msgs3msg6Clock_ISaIvEEEEEEEPcSt8functionIFT_DpT0_EE}

4 functions with some indirect sub-type change:

  [C] 'method std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>> rclcpp::AnySubscriptionCallback<rclcpp::SerializedMessage,std::allocator<void>>::create_serialized_message_unique_ptr_from_shared_ptr(const std::shared_ptr<constrclcpp::SerializedMessage>&)' at any_subscription_callback.hpp:490:1 has some indirect sub-type changes:
    implicit parameter 0 of type 'rclcpp::AnySubscriptionCallback<rclcpp::SerializedMessage,std::allocator<void>>*' has sub-type changes:
      in pointed to type 'class rclcpp::AnySubscriptionCallback<rclcpp::SerializedMessage,std::allocator<void>>' at any_subscription_callback.hpp:235:1:
        type size hasn't changed
        1 data member change:
          type of 'rclcpp::detail::AnySubscriptionCallbackHelper<rclcpp::SerializedMessage,std::allocator<void>,false,true>::variant_type callback_variant_' changed:
            underlying type 'class std::variant<std::function<void(constrclcpp::SerializedMessage&)>,std::function<void(constrclcpp::SerializedMessage&,constrclcpp::MessageInfo&)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<rclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>>' at variant:1425:1 changed:
              type name changed from 'std::variant<std::function<void(constrclcpp::SerializedMessage&)>,std::function<void(constrclcpp::SerializedMessage&,constrclcpp::MessageInfo&)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<rclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>>' to 'std::variant<std::function<void(constrclcpp::SerializedMessage&)>,std::function<void(constrclcpp::SerializedMessage&,constrclcpp::MessageInfo&)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&,constrclcpp::MessageInfo&)>>'
              type size hasn't changed
              2 base class deletions:
                struct std::_Enable_copy_move<true,true,true,true,std::variant<std::function<void(constrclcpp::SerializedMessage&)>,std::function<void(constrclcpp::SerializedMessage&,constrclcpp::MessageInfo&)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<rclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>>> at enable_special_members.h:89:1
                struct std::__detail::__variant::_Variant_base<std::function<void(constrclcpp::SerializedMessage&)>,std::function<void(constrclcpp::SerializedMessage&,constrclcpp::MessageInfo&)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<rclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>> at variant:757:1
              2 base class insertions:
                struct std::_Enable_copy_move<true,true,true,true,std::variant<std::function<void(constrclcpp::SerializedMessage&)>,std::function<void(constrclcpp::SerializedMessage&,constrclcpp::MessageInfo&)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&,constrclcpp::MessageInfo&)>>> at enable_special_members.h:89:1
                struct std::__detail::__variant::_Variant_base<std::function<void(constrclcpp::SerializedMessage&)>,std::function<void(constrclcpp::SerializedMessage&,constrclcpp::MessageInfo&)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&,constrclcpp::MessageInfo&)>> at variant:757:1

  [C] 'method void rclcpp::AnySubscriptionCallback<rosgraph_msgs::msg::Clock_<std::allocator<void>>,std::allocator<void>>::AnySubscriptionCallback(const rclcpp::AnySubscriptionCallback<rosgraph_msgs::msg::Clock_<std::allocator<void>>,std::allocator<void>>&)' at any_subscription_callback.hpp:365:1 has some indirect sub-type changes:
    Please note that the symbol of this function is _ZN6rclcpp23AnySubscriptionCallbackIN13rosgraph_msgs3msg6Clock_ISaIvEEES4_EC2ERKS6_
     and it aliases symbol: _ZN6rclcpp23AnySubscriptionCallbackIN13rosgraph_msgs3msg6Clock_ISaIvEEES4_EC1ERKS6_
    implicit parameter 0 of type 'rclcpp::AnySubscriptionCallback<rosgraph_msgs::msg::Clock_<std::allocator<void>>,std::allocator<void>>*' has sub-type changes:
      in pointed to type 'class rclcpp::AnySubscriptionCallback<rosgraph_msgs::msg::Clock_<std::allocator<void>>,std::allocator<void>>' at any_subscription_callback.hpp:235:1:
        type size hasn't changed
        1 data member change:
          type of 'rclcpp::detail::AnySubscriptionCallbackHelper<rosgraph_msgs::msg::Clock_<std::allocator<void>>,std::allocator<void>,false,false>::variant_type callback_variant_' changed:
            underlying type 'class std::variant<std::function<void(constrosgraph_msgs::msg::Clock_<std::allocator<void>>&)>,std::function<void(constrosgraph_msgs::msg::Clock_<std::allocator<void>>&,constrclcpp::MessageInfo&)>,std::function<void(constrclcpp::SerializedMessage&)>,std::function<void(constrclcpp::SerializedMessage&,constrclcpp::MessageInfo&)>,std::function<void(std::unique_ptr<rosgraph_msgs::msg::Clock_<std::allocator<void>>,std::default_delete<rosgraph_msgs::msg::Clock_<std::allocator<void>>>>)>,std::function<void(std::unique_ptr<rosgraph_msgs::msg::Clock_<std::allocator<void>>,std::default_delete<rosgraph_msgs::msg::Clock_<std::allocator<void>>>>,constrclcpp::MessageInfo&)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<constrosgraph_msgs::msg::Clock_<std::allocator<void>>>)>,std::function<void(std::shared_ptr<constrosgraph_msgs::msg::Clock_<std::allocator<void>>>,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>,std::function<void(conststd::shared_ptr<constrosgraph_msgs::msg::Clock_<std::allocator<void>>>&)>,std::function<void(conststd::shared_ptr<constrosgraph_msgs::msg::Clock_<std::allocator<void>>>&,constrclcpp::MessageInfo&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<rosgraph_msgs::msg::Clock_<std::allocator<void>>>)>,std::function<void(std::shared_ptr<rosgraph_msgs::msg::Clock_<std::allocator<void>>>,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<rclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>>' at variant:1425:1 changed:
              type name changed from 'std::variant<std::function<void(constrosgraph_msgs::msg::Clock_<std::allocator<void>>&)>,std::function<void(constrosgraph_msgs::msg::Clock_<std::allocator<void>>&,constrclcpp::MessageInfo&)>,std::function<void(constrclcpp::SerializedMessage&)>,std::function<void(constrclcpp::SerializedMessage&,constrclcpp::MessageInfo&)>,std::function<void(std::unique_ptr<rosgraph_msgs::msg::Clock_<std::allocator<void>>,std::default_delete<rosgraph_msgs::msg::Clock_<std::allocator<void>>>>)>,std::function<void(std::unique_ptr<rosgraph_msgs::msg::Clock_<std::allocator<void>>,std::default_delete<rosgraph_msgs::msg::Clock_<std::allocator<void>>>>,constrclcpp::MessageInfo&)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>)>,std::function<void(std::unique_ptr<rclcpp::SerializedMessage,std::default_delete<rclcpp::SerializedMessage>>,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<constrosgraph_msgs::msg::Clock_<std::allocator<void>>>)>,std::function<void(std::shared_ptr<constrosgraph_msgs::msg::Clock_<std::allocator<void>>>,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>)>,std::function<void(std::shared_ptr<constrclcpp::SerializedMessage>,constrclcpp::MessageInfo&)>,std::function<void(conststd::shared_ptr<constrosgraph_msgs::msg::Clock_<std::allocator<void>>>&)>,std::function<void(conststd::shared_ptr<constrosgraph_msgs::msg::Clock_<std::allocator<void>>>&,constrclcpp::MessageInfo&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&)>,std::function<void(conststd::shared_ptr<constrclcpp::SerializedMessage>&,constrclcpp::MessageInfo&)>,std::function<void(std::shared_ptr<rosgraph_msgs::msg::Clock_<std::allocator<void>>>)>,std::function<void(std::shared_ptr<rosgraph_msgs::msg::Clock_<std::allocator<void>>>,constrclcpp::
... (report truncated; the full report is in the check run artifacts: https://github.com/ros2/rclcpp/actions/runs/46059656988)
✅ librclcpp_action.so — full abidiff report

Compared:

  • Base: lib-base/librclcpp_action.so
  • Head: lib-pr/librclcpp_action.so @ 27a77ae
(empty report — no differences printed by abidiff)
✅ librclcpp_lifecycle.so — full abidiff report

Compared:

  • Base: lib-base/librclcpp_lifecycle.so
  • Head: lib-pr/librclcpp_lifecycle.so @ 27a77ae
(empty report — no differences printed by abidiff)

Updated for commit 27a77ae · check run · suppressions: /home/runner/work/_temp/ros2-abi-suppressions.txt

@ahcorde

ahcorde commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Pulls: #3449
Gist: https://gist.githubusercontent.com/ahcorde/a44592aa1e818f4bf2d7da14959c8b53/raw/7b3cf66641d8f1b1d7e522a839931ff57664038e/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/21342

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

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]>

@jmachowinski jmachowinski 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.

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 mini-1235 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@christophebedard

Copy link
Copy Markdown
Member Author

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.

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.

@christophebedard
christophebedard marked this pull request as draft November 27, 2026 19:15
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]>
@christophebedard

Copy link
Copy Markdown
Member Author

How do the compiler errors look like for this now ? 2 pages of wall of template failue ?

not bad? It's a single error with the static_assert message, and no other errors. Using a simple listener node with a [this](std_msgs::msg::String::SharedPtr msg) callback callback, it will look like this (same with other variants: MessageInfo, SerializedMessage, std::bind, or const std::shared_ptr<MessageT> &):

GCC output (15.2)
Starting >>> my_package
--- stderr: my_package
In file included from /opt/ros/rolling/include/rclcpp/rclcpp/subscription_base.hpp:31,
                 from /opt/ros/rolling/include/rclcpp/rclcpp/callback_group.hpp:29,
                 from /opt/ros/rolling/include/rclcpp/rclcpp/any_executable.hpp:20,
                 from /opt/ros/rolling/include/rclcpp/rclcpp/executors/executor_entities_collection.hpp:23,
                 from /opt/ros/rolling/include/rclcpp/rclcpp/executor.hpp:36,
                 from /opt/ros/rolling/include/rclcpp/rclcpp/executors/multi_threaded_executor.hpp:25,
                 from /opt/ros/rolling/include/rclcpp/rclcpp/executors.hpp:21,
                 from /opt/ros/rolling/include/rclcpp/rclcpp/rclcpp.hpp:177,
                 from /tmp/ws/src/my_package/src/listener.cpp:3:
/opt/ros/rolling/include/rclcpp/rclcpp/any_subscription_callback.hpp: In instantiation of ‘rclcpp::AnySubscriptionCallback<MessageT, AllocatorT> rclcpp::AnySubscriptionCallback<MessageT, AllocatorT>::set(CallbackT) [with CallbackT = Listener::Listener()::<lambda(std_msgs::msg::String_<std::allocator<void> >::SharedPtr)>; MessageT = std_msgs::msg::String_<std::allocator<void> >; AllocatorT = std::allocator<void>]’:
/opt/ros/rolling/include/rclcpp/rclcpp/subscription_factory.hpp:89:32:   required from ‘rclcpp::SubscriptionFactory rclcpp::create_subscription_factory(CallbackT&&, const SubscriptionOptionsWithAllocator<AllocatorT>&, typename MessageMemoryStrategyT::SharedPtr) [with MessageT = std_msgs::msg::String_<std::allocator<void> >; CallbackT = Listener::Listener()::<lambda(std_msgs::msg::String_<std::allocator<void> >::SharedPtr)>; AllocatorT = std::allocator<void>; SubscriptionT = Subscription<std_msgs::msg::String_<std::allocator<void> > >; MessageMemoryStrategyT = message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<std::allocator<void> >, std::allocator<void> >; typename MessageMemoryStrategyT::SharedPtr = std::shared_ptr<message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<std::allocator<void> >, std::allocator<void> > >]’
   89 |   any_subscription_callback.set(std::forward<CallbackT>(callback));
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/ros/rolling/include/rclcpp/rclcpp/create_subscription.hpp:67:63:   required from ‘std::shared_ptr<ROSMessageT> rclcpp::detail::create_subscription(NodeParametersT&, NodeTopicsT&, const std::string&, const rclcpp::QoS&, CallbackT&&, const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT>&, typename MessageMemoryStrategyT::SharedPtr) [with MessageT = std_msgs::msg::String_<std::allocator<void> >; CallbackT = Listener::Listener()::<lambda(std_msgs::msg::String_<std::allocator<void> >::SharedPtr)>; AllocatorT = std::allocator<void>; SubscriptionT = rclcpp::Subscription<std_msgs::msg::String_<std::allocator<void> > >; MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<std::allocator<void> >, std::allocator<void> >; NodeParametersT = rclcpp::Node; NodeTopicsT = rclcpp::Node; std::string = std::__cxx11::basic_string<char>; typename MessageMemoryStrategyT::SharedPtr = std::shared_ptr<rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<std::allocator<void> >, std::allocator<void> > >]’
   67 |   auto factory = rclcpp::create_subscription_factory<MessageT>(
      |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
   68 |     std::forward<CallbackT>(callback),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                         
   69 |     options,
      |     ~~~~~~~~                                                   
   70 |     msg_mem_strat
      |     ~~~~~~~~~~~~~                                              
   71 |   );
      |   ~                                                            
/opt/ros/rolling/include/rclcpp/rclcpp/create_subscription.hpp:134:76:   required from ‘std::shared_ptr<ROSMessageT> rclcpp::create_subscription(NodeT&, const std::string&, const QoS&, CallbackT&&, const SubscriptionOptionsWithAllocator<AllocatorT>&, typename MessageMemoryStrategyT::SharedPtr) [with MessageT = std_msgs::msg::String_<std::allocator<void> >; CallbackT = Listener::Listener()::<lambda(std_msgs::msg::String_<std::allocator<void> >::SharedPtr)>; AllocatorT = std::allocator<void>; SubscriptionT = Subscription<std_msgs::msg::String_<std::allocator<void> > >; MessageMemoryStrategyT = message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<std::allocator<void> >, std::allocator<void> >; NodeT = Node; std::string = std::__cxx11::basic_string<char>; typename MessageMemoryStrategyT::SharedPtr = std::shared_ptr<message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<std::allocator<void> >, std::allocator<void> > >]’
  133 |   return rclcpp::detail::create_subscription<
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                               
  134 |     MessageT, CallbackT, AllocatorT, SubscriptionT, MessageMemoryStrategyT>(
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
  135 |     node, node, topic_name, qos, std::forward<CallbackT>(callback), options, msg_mem_strat);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/ros/rolling/include/rclcpp/rclcpp/node_impl.hpp:92:47:   required from ‘std::shared_ptr<ROSMessageT> rclcpp::Node::create_subscription(const std::string&, const rclcpp::QoS&, CallbackT&&, const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT>&, typename MessageMemoryStrategyT::SharedPtr) [with MessageT = std_msgs::msg::String_<std::allocator<void> >; CallbackT = Listener::Listener()::<lambda(std_msgs::msg::String_<std::allocator<void> >::SharedPtr)>; AllocatorT = std::allocator<void>; SubscriptionT = rclcpp::Subscription<std_msgs::msg::String_<std::allocator<void> > >; MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<std::allocator<void> >, std::allocator<void> >; std::string = std::__cxx11::basic_string<char>; typename MessageMemoryStrategyT::SharedPtr = std::shared_ptr<rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<std::allocator<void> >, std::allocator<void> > >]’
   92 |   return rclcpp::create_subscription<MessageT>(
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
   93 |     *this,
      |     ~~~~~~                                     
   94 |     extend_name_with_sub_namespace(topic_name, this->get_sub_namespace()),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   95 |     qos,
      |     ~~~~                                       
   96 |     std::forward<CallbackT>(callback),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~         
   97 |     options,
      |     ~~~~~~~~                                   
   98 |     msg_mem_strat);
      |     ~~~~~~~~~~~~~~                             
/tmp/ws/src/my_package/src/listener.cpp:12:63:   required from here
   12 |     subscription_ = create_subscription<std_msgs::msg::String>(
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
   13 |       "topic", 10,
      |       ~~~~~~~~~~~~                                             
   14 |       [this](std_msgs::msg::String::SharedPtr msg) {
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~           
   15 |         RCLCPP_INFO(get_logger(), "I heard: '%s'", msg->data.c_str());
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   16 |       });
      |       ~~                                                       
/opt/ros/rolling/include/rclcpp/rclcpp/any_subscription_callback.hpp:365:10: error: static assertion failed: subscription callbacks taking a std::shared_ptr to a non-const message are not supported, use std::shared_ptr<const MessageT> instead
  365 |         !is_shared_ptr_to_non_const_message,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/ros/rolling/include/rclcpp/rclcpp/any_subscription_callback.hpp:365:10: note: ‘!(bool)is_shared_ptr_to_non_const_message’ evaluates to false
gmake[2]: *** [CMakeFiles/listener.dir/build.make:79: CMakeFiles/listener.dir/src/listener.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:153: CMakeFiles/listener.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
---
Failed   <<< my_package [2.77s, exited with code 2]

Summary: 0 packages finished [2.87s]
  1 package failed: my_package
  1 package had stderr output: my_package
Clang output (21.1)
Starting >>> my_package
--- stderr: my_package
In file included from /tmp/ws/src/my_package/src/listener.cpp:3:
In file included from /opt/ros/rolling/include/rclcpp/rclcpp/rclcpp.hpp:177:
In file included from /opt/ros/rolling/include/rclcpp/rclcpp/executors.hpp:21:
In file included from /opt/ros/rolling/include/rclcpp/rclcpp/executors/multi_threaded_executor.hpp:25:
In file included from /opt/ros/rolling/include/rclcpp/rclcpp/executor.hpp:36:
In file included from /opt/ros/rolling/include/rclcpp/rclcpp/executors/executor_entities_collection.hpp:23:
In file included from /opt/ros/rolling/include/rclcpp/rclcpp/any_executable.hpp:20:
In file included from /opt/ros/rolling/include/rclcpp/rclcpp/callback_group.hpp:29:
In file included from /opt/ros/rolling/include/rclcpp/rclcpp/subscription_base.hpp:31:
/opt/ros/rolling/include/rclcpp/rclcpp/any_subscription_callback.hpp:365:9: error: static assertion failed due to requirement '!is_shared_ptr_to_non_const_message': subscription callbacks taking a std::shared_ptr to a non-const message are not supported, use std::shared_ptr<const MessageT> instead
  365 |         !is_shared_ptr_to_non_const_message,
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/ros/rolling/include/rclcpp/rclcpp/subscription_factory.hpp:89:29: note: in instantiation of function template specialization 'rclcpp::AnySubscriptionCallback<std_msgs::msg::String_<std::allocator<void>>>::set<(lambda at /tmp/ws/src/my_package/src/listener.cpp:14:7)>' requested here
   89 |   any_subscription_callback.set(std::forward<CallbackT>(callback));
      |                             ^
/opt/ros/rolling/include/rclcpp/rclcpp/create_subscription.hpp:67:26: note: in instantiation of function template specialization 'rclcpp::create_subscription_factory<std_msgs::msg::String_<std::allocator<void>>, (lambda at /tmp/ws/src/my_package/src/listener.cpp:14:7), std::allocator<void>, rclcpp::Subscription<std_msgs::msg::String_<std::allocator<void>>>, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<std::allocator<void>>>>' requested here
   67 |   auto factory = rclcpp::create_subscription_factory<MessageT>(
      |                          ^
/opt/ros/rolling/include/rclcpp/rclcpp/create_subscription.hpp:133:26: note: in instantiation of function template specialization 'rclcpp::detail::create_subscription<std_msgs::msg::String_<std::allocator<void>>, (lambda at /tmp/ws/src/my_package/src/listener.cpp:14:7), std::allocator<void>, rclcpp::Subscription<std_msgs::msg::String_<std::allocator<void>>>, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<std::allocator<void>>>, rclcpp::Node, rclcpp::Node>' requested here
  133 |   return rclcpp::detail::create_subscription<
      |                          ^
/opt/ros/rolling/include/rclcpp/rclcpp/node_impl.hpp:92:18: note: in instantiation of function template specialization 'rclcpp::create_subscription<std_msgs::msg::String_<std::allocator<void>>, (lambda at /tmp/ws/src/my_package/src/listener.cpp:14:7), std::allocator<void>, rclcpp::Subscription<std_msgs::msg::String_<std::allocator<void>>>, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<std::allocator<void>>>, rclcpp::Node>' requested here
   92 |   return rclcpp::create_subscription<MessageT>(
      |                  ^
/tmp/ws/src/my_package/src/listener.cpp:12:21: note: in instantiation of function template specialization 'rclcpp::Node::create_subscription<std_msgs::msg::String_<std::allocator<void>>, (lambda at /tmp/ws/src/my_package/src/listener.cpp:14:7), std::allocator<void>, rclcpp::Subscription<std_msgs::msg::String_<std::allocator<void>>>, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<std::allocator<void>>>>' requested here
   12 |     subscription_ = create_subscription<std_msgs::msg::String>(
      |                     ^
1 error generated.
gmake[2]: *** [CMakeFiles/listener.dir/build.make:79: CMakeFiles/listener.dir/src/listener.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:153: CMakeFiles/listener.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
---
Failed   <<< my_package [2.91s, exited with code 2]

Summary: 0 packages finished [3.03s]
  1 package failed: my_package
  1 package had stderr output: my_package

If yes, can we make this nicer now that we got the power of c++20 concepts ?

It seems like using concepts would require changes to Node, LifecycleNode, the free rclcpp::create_subscription() functions, create_subscription_factory()), and we'd still need the static_assert for code that uses AnySubscriptionCallback directly. The error would move to the call site and get shorter, but we'd lose the custom message; it's not as "friendly." I would keep the simple static_assert, at least for now (although it seems like we won't proceed with this PR until N-turtle anyway).

Clang output with a concept
/tmp/ws/src/my_package/src/listener.cpp:12:21: error: no matching member function for call to 'create_subscription'
   12 |     subscription_ = create_subscription<std_msgs::msg::String>(
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/ros/rolling/include/rclcpp/rclcpp/node_impl.hpp:86:7: note: candidate template ignored: constraints not satisfied [with MessageT = std_msgs::msg::String, CallbackT = (lambda at /tmp/ws/src/my_package/src/listener.cpp:14:7), AllocatorT = std::allocator<void>, SubscriptionT = rclcpp::Subscription<std_msgs::msg::String, std::allocator<void>>, MessageMemoryStrategyT = typename rclcpp::Subscription<std_msgs::msg::String, std::allocator<void>>::MessageMemoryStrategyType]
   86 | Node::create_subscription(
      |       ^
/opt/ros/rolling/include/rclcpp/rclcpp/node.hpp:219:12: note: because 'SubscriptionCallbackDoesNotTakeSharedPtrToNonConstMessage<(lambda at /tmp/ws/src/my_package/src/listener.cpp:14:7), std_msgs::msg::String_<std::allocator<void>>>' evaluated to false
  219 |   requires SubscriptionCallbackDoesNotTakeSharedPtrToNonConstMessage<CallbackT, MessageT>
      |            ^
/opt/ros/rolling/include/rclcpp/rclcpp/detail/subscription_callback_concepts.hpp:37:3: note: because '!detail::takes_shared_ptr_to_non_const_message<std_msgs::msg::String_<std::allocator<void>>, std::decay_t<(lambda at /tmp/ws/src/my_package/src/listener.cpp:14:7)>>::value' evaluated to false
   37 |   !detail::takes_shared_ptr_to_non_const_message<MessageT, std::decay_t<CallbackT>>::value;
      |   ^
1 error generated.

@christophebedard

Copy link
Copy Markdown
Member Author

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.

@mini-1235 I've got a PR for proper deprecation warnings (on both gcc and clang): #3450

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants