ros2 / ros2/rclcpp

AnySubscriptionCallback doesn't accept `std::bind` callbacks with bound arguments

Open
#2,429 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
C++
Stars
805
Forks
564
Avg merge
1d 17h
Merged PRs (30d)
27

Description

Bug report

Required Info:

  • Operating System:
    • Ubuntu 22.04
  • Installation type:
    • from source
  • Version or commit hash:
    • rolling
  • DDS implementation:
    • Fast-RTPS
  • Client library (if applicable):
    • rclcpp
Steps to reproduce issue
  1. Build rclcpp on a version after https://github.com/ros2/rclcpp/pull/1928
  2. Try to build for example foxglove-bridge
Expected behavior

std::bind(&FoxgloveBridge::rosMessageHandler, this, channelId, clientHandle, _1), (source) is cast to std::function from any_subscription_callback.hpp

Actual behavior

Screenshot from 2024-02-19 10-56-06

Additional information

For example std::bind(&Class::method, this, std::placeholders::_1) (without bound arguments) will build fine

We also were able to fix the issue by casting the callback to std::function before passing it to the subscription

auto subscriber = this->create_generic_subscription(
      topic, datatype, qos,
      static_cast<std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)>>(std::bind(&FoxgloveBridge::rosMessageHandler, this, channelId, clientHandle, _1)),
      subscriptionOptions);

Is this how it is supposed to be done now, or is there a bug in casting std::bind from any_subscription_callback.hpp?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in rclcpp/include/rclcpp/any_subscription_callback.hpp at the callback conversion referenced in the report, then reproduce the build through create_generic_subscription using the foxglove-bridge example. Compare std::bind callbacks with and without bound arguments and verify the subscription accepts the reported callback without a caller-side std::function cast.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.