ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org

ROS2 compatibility with C++20

Hi,
I’m working on a C++ application which uses some elements of ROS2 (Foxy). So far I’ve been working without issue in a mix of C++17 & C++20, compiling with g++9. I recently tried switching to g++10, to make use of some additional C++20 features, which resulted in some 2000 compilation errors from the ROS2 headers I was using.
As far as I can tell, they mostly boil down to the error:
no class template named ‘rebind’ in ‘class std::allocator’
…which I understand was deprecated in C++20, discussed e.g. here in a ROS 1 context: https://github.com/ros/gencpp/pull/51

There may be other issues too - I certainly haven’t done a deep dive here!

I was just wondering if there are any current plans for C++20 support in ROS2?

1 Like

There are not. We are just now upgrading to C++17 for the upcoming ROS 2 Galactic release:

https://www.ros.org/reps/rep-2000.html#galactic-geochelone-may-2021-may-2022

We’ll reconsider this in the next release after Galactic.

In the meantime, if there’s a change that can be made to allow it to work with C++20 without breaking compatibility with the other compiler versions we’re supporting, then we’d take a pull request like that.

I actually fixed that error on the master branches with Switch to std::allocator_traits. by clalancette · Pull Request #564 · ros2/rosidl · GitHub . So at least for Galactic, this should be better. I’m not at all confident that that change is API/ABI compatible, so it is doubtful I’ll port it back to Foxy.

As @wjwwood said, Galactic is targeting C++17, so most of our effort has been focused around that. We’ll have to discuss C++20 for a future release.

In general, we’re happy to take fixes to make the codebase more compliant with the newer C++ standards, as long as it doesn’t break the earlier standards we are actually targeting.

1 Like