Skip to content

Fix STLAllocator compatibility with GCC 15 and modern C++ standards#568

Open
wentasah wants to merge 1 commit intoOGRECave:v2-3from
wentasah:gcc15
Open

Fix STLAllocator compatibility with GCC 15 and modern C++ standards#568
wentasah wants to merge 1 commit intoOGRECave:v2-3from
wentasah:gcc15

Conversation

@wentasah
Copy link
Copy Markdown
Contributor

@wentasah wentasah commented Apr 9, 2026

Updated STLAllocator constructors to be compatible with modern C++ standard library containers:

  1. Made constructors constexpr: Added constexpr keyword to all constructors to make them compatible with modern C++ standard library containers that require constexpr allocators.

  2. Removed explicit from default constructor: The default constructor was marked as explicit, which prevented it from being used in implicit initialization contexts (like {}-initialization). Standard library containers expect allocators to have non-explicit default constructors.

  3. Conditionally made destructor constexpr: Added a preprocessor check to only make the destructor constexpr in C++20 and later, since constexpr destructors are not available in earlier C++ standards.

These changes fix compilation errors with GCC 15 where the hashtable implementation tries to use {} initialization on the allocator member, which requires a non-explicit constexpr default constructor.


Note: this fixes the same problem as #564, but was entirely AI generated. I'm not sure whether you have some AI policy so feel free to disregard it if it violates your policy.

Updated STLAllocator constructors to be compatible with modern C++
standard library containers:

1. Made constructors constexpr: Added constexpr keyword to all
   constructors to make them compatible with modern C++ standard library
   containers that require constexpr allocators.

2. Removed explicit from default constructor: The default constructor
   was marked as explicit, which prevented it from being used in
   implicit initialization contexts (like {}-initialization). Standard
   library containers expect allocators to have non-explicit default
   constructors.

3. Conditionally made destructor constexpr: Added a preprocessor check
   to only make the destructor constexpr in C++20 and later, since
   constexpr destructors are not available in earlier C++ standards.

These changes fix compilation errors with GCC 15 where the hashtable
implementation tries to use {} initialization on the allocator member,
which requires a non-explicit constexpr default constructor.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@darksylinc
Copy link
Copy Markdown
Member

What's the take from Gazebo team?

They don't like changes that break the ABI and this almost certainly an ABI-breaking change (I didn't run the abi checker to confirm).

There was a similar discussion with #541 where Apple broke support. Fortunately we avoided it entirely because the affected component wasn't actually in use.

Given that at this point the v2-3 branch is basically "whatever gazebo is doing", it may be solvable by simply doing #ifdef GCC >= 15 (not actual macro name), thus Gazebo ABI compiled with GCC 15 is compatible with Ogre 2.3 compiled with GCC 15; while Gazebo GCC 14 remains compatible with Ogre 2.3 compiled with GCC 15.

@wentasah
Copy link
Copy Markdown
Contributor Author

wentasah commented Apr 9, 2026

@scpeters Can you answer the above?

We're using this patch in nix-ros-overlay and it works fine, but ABI compatibility is not that important in Nix ecosystem as elsewhere, and I have no clue how and where is this used.

@scpeters
Copy link
Copy Markdown
Contributor

@scpeters Can you answer the above?

We're using this patch in nix-ros-overlay and it works fine, but ABI compatibility is not that important in Nix ecosystem as elsewhere, and I have no clue how and where is this used.

I will discuss with the gazebo team

cc @azeey @iche033 @j-rivero

@j-rivero
Copy link
Copy Markdown

What's the take from Gazebo team?

Thanks for checking. Given our model of loading plugins for gz-rendering, we can probably deal with an ABI breakage without too much problem for the end users that load the gz-rendering-ogre2 plugin directly from our binaries.

Said that, I known that we declared the Semantic Versioning starting with 3.x but might be a good practice try to keep it stable if we can. For this case, we can potentially add a compiler flag (default to OFF) that brings the patches in this PR (something like -DUSE_MODERN_CXX) so the people that needs the patch enable it in their building metadata while the software maintains the ABI stability for all the 2.3 potential consumers out there.

bazel-io pushed a commit to bazelbuild/bazel-central-registry that referenced this pull request Apr 16, 2026
Changes:

* added `fix_stlallocator_gcc15.patch` patch (from
OGRECave/ogre-next#568) that fixes compilation
with gcc 15
* changed `OGRE_SET_DISABLE_JSON` to `0` in `BUILD.bazel` to enable
features that require json, e.g. `VctVoxelizer`. The `ogre-main` target
links against `rapidjson` already so this change just flips the switch.
* added `load(..)` statements for `cc_library` and `cc_binary` so it's
compatible with bazel version 9.x

Signed-off-by: Ian Chen <iche@intrinsic.ai>
@wentasah
Copy link
Copy Markdown
Contributor Author

we can potentially add a compiler flag (default to OFF) that brings the patches in this PR (something like -DUSE_MODERN_CXX) so the people that needs the patch enable it in their building metadata while the software maintains the ABI stability for all the 2.3 potential consumers out there

I'm fine with adding -DUSE_MODERN_CXX, but I was curious about the ABI incompatibilities and run the change through abi-compliance-checker and it reported 100% compatibility for libOgreMain.so. The result for other libraries was the same. If the tool can be trusted, changes seem not to be necessary. But the tool was last updated 5 years ago, so I can image it might have missed some incompatibilities related to modern C++. Does anybody have experience with reliability of abi-compliance-checker reports?

@j-rivero
Copy link
Copy Markdown

. Does anybody have experience with reliability of abi-compliance-checker reports?

We have been using it for the last decade in Gazebo and it we did not have any serious problem that it was not detected. So it is old but still works I would say.

Looking now more into the changes i think that they affect to the source semantics but not to the binary layer generated to my eyes.

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.

4 participants