← Back to Pull requests

Fix non-const shared_ptr callback deprecation warnings with GCC #3450

Closed
unknown closed this pull request without merging on Nov 29, 2026 01:41 UTC
View on GitHub
unknown unknown commented on Nov 27, 2026 23:55 UTC
Author

Description

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

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 the create_subscription() or create_generic_subscription() call. Use std::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 the Node and LifecycleNode member functions (once for the function template and once for its specialization).

<details><summary>Example with GCC 15</summary>

/tmp/dws/src/my_package/src/listener.cpp: In constructor ‘Listener::Listener()’:
/tmp/dws/src/my_package/src/listener.cpp:12:63: warning: ‘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> > >]’ is deprecated: subscription callbacks taking a std::shared_ptr to a non-const message are deprecated, use std::shared_ptr<const MessageT> instead [-Wdeprecated-declarations]
   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 |       });
      |       ~~
In file included from /ws/install/rclcpp/include/rclcpp/rclcpp/node.hpp:1760,
                 from /ws/install/rclcpp/include/rclcpp/rclcpp/executors.hpp:25,
                 from /ws/install/rclcpp/include/rclcpp/rclcpp/rclcpp.hpp:177,
                 from /tmp/dws/src/my_package/src/listener.cpp:3:
/ws/install/rclcpp/include/rclcpp/rclcpp/node_impl.hpp:109:1: note: declared here
  109 | Node::create_subscription(
      | ^~~~

</details>

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.

Diff: 529 lines (+396 / -133) across 6 files Reviewer: mini-1235 Review duration: 1546m
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.48) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 529 lines diff across 6 files
0.48
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.375
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3450"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 47.9% (MEDIUM) · Higher = larger blast radius
47.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 20.7% · Safe to merge
20.7%
Repository