ros2 / ros2/rclcpp

Allow Node functionality to use methods with noexcept modifiers.

Open
#2,654 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Feature request

Feature description

The rclcpp::Node methods

  • create_subscription()
  • create_wall_timer()
  • create_service()
  • add_on_set_parameters_callback(), remove_on_set_parameters_callback(), set_on_parameters_set_callback()
    all take a callback as parameter. I think, the callback methods should be able to be marked as noexcept. For example, this currently does not work:
#include <chrono>
#include <functional>
#include <memory>

#include <rclcpp/rclcpp.hpp>

class DemoNode : public rclcpp::Node {
 public:
  DemoNode() : rclcpp::Node("demo127") {
    this->create_wall_timer(
      std::chrono::milliseconds(100),
      std::bind(&DemoNode::read, this));
    }
	
 private:
  void read() noexcept {
    // etc.
  }
};

int main(int argc, char ** argv) {
  rclcpp::init(argc, argv);
  auto node = std::make_shared<DemoNode>();
  rclcpp::spin(node);
  return rclcpp::shutdown();
}

Won't compile with this error:

error: no matching function for call to ‘DemoNode::create_wall_timer(std::chrono::milliseconds, std::_Bind_helper<false, void (DemoNode::*)() noexcept, DemoNode*>::type)

Removing the noexcept modifier fixes the issue.

I think it should be possible to add the noexcept modifier to callbacks in timers, services, etc.

Going further, it may only make sense to have these callbacks forced to be noexcept?

Implementation considerations

noexcept has only been available since C++11.

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 with the listed rclcpp::Node methods and reproduce the DemoNode example using a noexcept read callback. Determine how callback acceptance should work for subscriptions, timers, services, and parameter callbacks, including whether callbacks should be required to be noexcept. Done means the example and corresponding callback uses compile successfully with noexcept modifiers.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design
Issue type
Feature
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.