Skip to content

Patch ros2-rclcpp to avoid GCC 15 -Werror=uninitialized in MessageMemoryStrategy::create_default() - #254

Merged
traversaro merged 1 commit into
RoboStack:mainfrom
benjaminholdennearearth:benjaminholdennearearth-patch-1
Nov 26, 2026
Merged

traversaro merged 1 commit into
RoboStack:mainfrom
benjaminholdennearearth:benjaminholdennearearth-patch-1

Conversation

@benjaminholdennearearth

Copy link
Copy Markdown
Contributor

Summary

In rclcpp::message_memory_strategy::MessageMemoryStrategy::create_default(), avoid heap-allocating a temporary std::shared_ptr<std::allocator<void>> when Alloc is the default std::allocator<void>, and call the existing 0-arg MessageMemoryStrategy() constructor directly instead.

Motivation

  1. Eliminates a redundant heap allocation on every default create_subscription() / MessageMemoryStrategy::create_default() call: currently std::make_shared<Alloc>() allocates a control block + empty std::allocator<void>, passes it to MessageMemoryStrategy(std::shared_ptr<Alloc>), which dereferences it and immediately destroys the temporary shared_ptr.
  2. Fixes a GCC 15 -Werror=uninitialized failure in downstream C++ code compiled with -O2 -Wall -Wextra -Werror: in constructors with many create_subscription() calls, GCC 15.3.0's SRA pass emits a false-positive -Wuninitialized warning on the scalarized empty std::allocator<void> inside std::make_shared<std::allocator<void>>():
    In function 'std::shared_ptr<std::_NonArray<_Tp> > std::make_shared(_Args&& ...) [with _Tp = allocator<void>; _Args = {}]',
        inlined from 'static rclcpp::message_memory_strategy::MessageMemoryStrategy<MessageT, Alloc>::SharedPtr rclcpp::message_memory_strategy::MessageMemoryStrategy<MessageT, Alloc>::create_default() [with MessageT = nav_msgs::msg::Odometry_<std::allocator<void> >; Alloc = std::allocator<void>]' at .../rclcpp/message_memory_strategy.hpp:91:92,
        inlined from '...':
    .../gcc/x86_64-conda-linux-gnu/15.3.0/include/c++/bits/shared_ptr.h:1008:60: error: 'SR.93144' is used uninitialized [-Werror=uninitialized]
     1008 |                              std::forward<_Args>(__args)...);
          |                                                            ^
    .../rclcpp/message_memory_strategy.hpp:91:92: note: 'SR.93144' was declared here
       91 |     return std::make_shared<MessageMemoryStrategy<MessageT, Alloc>>(std::make_shared<Alloc>());
          |                                                                     ~~~~~~~~~~~~~~~~~~~~~~~^~
    

Implementation Details

  • Uses if constexpr (std::is_same_v<Alloc, std::allocator<void>>) — matching the exact pattern already used in both MessageMemoryStrategy constructors directly above create_default().
  • Preserves existing behavior 100% for custom stateful Alloc types (which still share a single default-constructed Alloc instance across message_allocator_, serialized_message_allocator_, and buffer_allocator_).

Testing The Patch

pixi run rs jazzy generate-recipes: Generated ros2-rclcpp (and legacy ros-jazzy-rclcpp) at build_number: 32.
pixi run rs jazzy check-patches --recipe ros2-rclcpp: Passed (1/1) — All patches applied cleanly. across all platforms (linux, osx, win, emscripten).
pixi run rs check: # check: ok — all distributions assemble, YAML sorting and generated files are up to date.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

ABI check (linux-64)

humble linux-64: 1 to review (changed headers), 4 can be bumped on their own
package released → PR verdict details
rclcpp 16.0.23 (build 25) → 16.0.23 compatible: no ABI change 1 headers changed (check for layout/inline changes): rclcpp/rclcpp/message_memory_strategy.hpp
4 packages can be bumped on their own (compatible: 2, no libraries: 2)
package released → PR verdict details
moveit-core 2.5.10 (build 25) → 2.5.10 compatible: no ABI change headers unchanged
new dependencies: bullet-cpp >=3.25,<3.26
dropped dependencies: bullet
ros-gz-bridge 0.244.27 (build 25) → 0.244.27 compatible: no ABI change headers unchanged
pins changed: libignition-transport11 >=11.4.3,<12 → >=11.4.1,<12
new dependencies: libabseil * cxx17*, libprotobuf >=7.35.1,<7.35.2
ros-gz-image 0.244.27 (build 25) → 0.244.27 no libraries: nothing to compare pins changed: libignition-transport11 >=11.4.3,<12 → >=11.4.1,<12
new dependencies: libabseil * cxx17*, libprotobuf >=7.35.1,<7.35.2
tf2-bullet 0.25.24 (build 25) → 0.25.24 no libraries: nothing to compare headers unchanged
new dependencies: bullet-cpp >=3.25,<3.26
dropped dependencies: bullet

Compared with the newest builds on https://conda.anaconda.org/robostack-humble/linux-64.

jazzy linux-64: 1 to review (changed headers), 6 can be bumped on their own
package released → PR verdict details
rclcpp 28.1.23 (build 31) → 28.1.23 compatible: no ABI change 1 headers changed (check for layout/inline changes): rclcpp/rclcpp/message_memory_strategy.hpp
6 packages can be bumped on their own (compatible: 2, no libraries: 4)
package released → PR verdict details
moveit-core 2.12.4 (build 31) → 2.12.4 compatible: no ABI change headers unchanged
new dependencies: bullet-cpp >=3.25,<3.26
dropped dependencies: bullet
ros-gz-bridge 1.0.25 (build 31) → 1.0.25 compatible: no ABI change headers unchanged
new dependencies: libabseil * cxx17*, libprotobuf >=7.35.1,<7.35.2
gz-dartsim-vendor 0.0.3 (build 31) → 0.0.3 no libraries: nothing to compare new dependencies: bullet-cpp >=3.25,<3.26
dropped dependencies: bullet
gz-physics-vendor 0.0.10 (build 31) → 0.0.10 no libraries: nothing to compare new dependencies: bullet-cpp >=3.25,<3.26
dropped dependencies: bullet
ros-gz-image 1.0.25 (build 31) → 1.0.25 no libraries: nothing to compare new dependencies: libabseil * cxx17*, libprotobuf >=7.35.1,<7.35.2
tf2-bullet 0.36.23 (build 31) → 0.36.23 no libraries: nothing to compare headers unchanged
new dependencies: bullet-cpp >=3.25,<3.26
dropped dependencies: bullet

Compared with the newest builds on https://conda.anaconda.org/robostack-jazzy/linux-64.

lyrical linux-64: 1 to review (changed headers), 6 can be bumped on their own
package released → PR verdict details
rclcpp 32.0.3 (build 30) → 32.0.3 compatible: no ABI change 1 headers changed (check for layout/inline changes): rclcpp/rclcpp/message_memory_strategy.hpp
6 packages can be bumped on their own (compatible: 2, no libraries: 4)
package released → PR verdict details
moveit-core 2.15.2 (build 31) → 2.15.2 compatible: no ABI change headers unchanged
pins changed: python_abi 3.12.* _cp312 → 3.14. *_cp314
ros-gz-bridge 3.0.10 (build 30) → 3.0.10 compatible: no ABI change headers unchanged
new dependencies: libabseil * cxx17*, libprotobuf >=7.35.1,<7.35.2
gz-dartsim-vendor 0.1.3 (build 30) → 0.1.3 no libraries: nothing to compare pins changed: assimp >=6.0.5,<7 → >=6.0.6,<7
new dependencies: bullet-cpp >=3.25,<3.26
dropped dependencies: bullet
gz-physics-vendor 0.4.8 (build 30) → 0.4.8 no libraries: nothing to compare pins changed: gz-physics any → 9.*, libgz-physics >=9.5.2,<10 → >=9.6.1,<10
new dependencies: bullet-cpp >=3.25,<3.26
dropped dependencies: bullet
ros-gz-image 3.0.10 (build 30) → 3.0.10 no libraries: nothing to compare new dependencies: libabseil * cxx17*, libprotobuf >=7.35.1,<7.35.2
tf2-bullet 0.45.10 (build 30) → 0.45.10 no libraries: nothing to compare headers unchanged
new dependencies: bullet-cpp >=3.25,<3.26
dropped dependencies: bullet

Compared with the newest builds on https://repo.prefix.dev/robostack-lyrical/linux-64.

rolling linux-64: 1 to review (changed headers), 5 can be bumped on their own
package released → PR verdict details
rclcpp 33.1.0 (build 32) → 33.1.0 compatible: no ABI change 1 headers changed (check for layout/inline changes): rclcpp/rclcpp/message_memory_strategy.hpp
5 packages can be bumped on their own (compatible: 1, no libraries: 4)
package released → PR verdict details
ros-gz-bridge 4.0.2 (build 32) → 4.0.2 compatible: no ABI change headers unchanged
new dependencies: libabseil * cxx17*, libprotobuf >=7.35.1,<7.35.2
gz-dartsim-vendor 0.1.3 (build 32) → 0.1.3 no libraries: nothing to compare pins changed: assimp >=6.0.5,<7 → >=6.0.6,<7
new dependencies: bullet-cpp >=3.25,<3.26
dropped dependencies: bullet
gz-physics-vendor 0.5.4 (build 32) → 0.5.4 no libraries: nothing to compare pins changed: gz-physics any → 9.*, libgz-physics >=9.5.2,<10 → >=9.6.1,<10
new dependencies: bullet-cpp >=3.25,<3.26
dropped dependencies: bullet
ros-gz-image 4.0.2 (build 32) → 4.0.2 no libraries: nothing to compare new dependencies: libabseil * cxx17*, libprotobuf >=7.35.1,<7.35.2
tf2-bullet 0.46.4 (build 32) → 0.46.4 no libraries: nothing to compare headers unchanged
new dependencies: bullet-cpp >=3.25,<3.26
dropped dependencies: bullet

Compared with the newest builds on https://repo.prefix.dev/robostack-rolling/linux-64.

About this check

Each package this pull request built, compared with its newest released build (tools/abi_check.py, libabigail):

  • compatible / additions: the package can be bumped on its own;
  • soname / incompatible: the packages that depend on it need a rebuild (build number bump) in the same pull request.

Exported symbols are compared (the released packages are stripped, so struct layouts aren't); unchanged installed headers rule out layout and inline changes, changed ones are listed for review. Dependents to rebuild are the released ones linking to a changed library. A changed pin is part of the comparison.

@traversaro

Copy link
Copy Markdown
Member

Why only in Jazzy? Can you also contribute this upstream? Thanks!

@benjaminholdennearearth

Copy link
Copy Markdown
Contributor Author

Why only in Jazzy? Can you also contribute this upstream? Thanks!

I only tested in Jazzy. I can look to put this in all distros and look to contribute upstream.

…s all distros

Avoid unnecessary std::make_shared<std::allocator<void>>() in
MessageMemoryStrategy::create_default(), which triggers a GCC 15
-Werror=uninitialized false positive in downstream packages.

- Place ros2-rclcpp.patch in shared/patch/ (covering humble, jazzy, rolling)
- Add matching distros/lyrical/patch/ros2-rclcpp.patch alongside its
  existing ros2-rclcpp.win.patch (distro patches override shared patches)
- Bump rclcpp build_number in humble (26), jazzy (32), lyrical (31), and
  rolling (33)
@benjaminholdennearearth
benjaminholdennearearth force-pushed the benjaminholdennearearth-patch-1 branch from d255310 to ab22445 Compare November 25, 2026 13:25
@benjaminholdennearearth

Copy link
Copy Markdown
Contributor Author

Here is the upstream PR: ros2/rclcpp#3436

@benjaminholdennearearth benjaminholdennearearth changed the title jazzy: patch ros2-rclcpp to avoid GCC 15 -Werror=uninitialized in MessageMemoryStrategy::create_default() Patch ros2-rclcpp to avoid GCC 15 -Werror=uninitialized in MessageMemoryStrategy::create_default() Nov 25, 2026
@Tobias-Fischer

Copy link
Copy Markdown
Collaborator

Are we good to merge @traversaro?

@traversaro
traversaro merged commit 773fcd3 into RoboStack:main Nov 26, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants