Skip to content

Fix compilation with gcc16 - #1719

Open
bmwiedemann wants to merge 1 commit into
redeclipse:masterfrom
bmwiedemann:gcc16
Open

Fix compilation with gcc16#1719
bmwiedemann wants to merge 1 commit into
redeclipse:masterfrom
bmwiedemann:gcc16

Conversation

@bmwiedemann

@bmwiedemann bmwiedemann commented Aug 4, 2026

Copy link
Copy Markdown

Do not redefine the standard placement new/delete operators

tools.h defined the placement forms of operator new/delete itself instead of pulling them in from <new>. That only works as long as no standard library header defining them has been included before.

As of GCC 16, libstdc++ includes <new> from <bits/stl_iterator.h>, which cube.h drags in via <math.h> -> <cmath>, so the definitions in tools.h now collide with the ones from the standard library and the build fails:

In file included from shared/cube.h:57:
shared/tools.h:38:14: error: redefinition of 'void* operator new(size_t, void*)'
   38 | inline void *operator new(size_t, void *p) { return p; }
      |              ^~~~~~~~
/usr/include/c++/16/new:168:7: note: 'void* operator new(std::size_t, void*)' previously defined here

Include <new> and drop the hand-written definitions. The standard ones are inline and behave identically - and, unlike ours, are constexpr where the standard requires it. The custom operator new(size_t, bool) overloads are not affected.

Do not redefine the standard placement new/delete operators

tools.h defined the placement forms of operator new/delete itself
instead of pulling them in from <new>.  That only works as long as no
standard library header defining them has been included before.

As of GCC 16, libstdc++ includes <new> from <bits/stl_iterator.h>,
which cube.h drags in via <math.h> -> <cmath>, so the definitions in
tools.h now collide with the ones from the standard library and the
build fails:

  In file included from shared/cube.h:57:
  shared/tools.h:38:14: error: redefinition of 'void* operator new(size_t, void*)'
     38 | inline void *operator new(size_t, void *p) { return p; }
        |              ^~~~~~~~
  /usr/include/c++/16/new:168:7: note: 'void* operator new(std::size_t, void*)' previously defined here

Include <new> and drop the hand-written definitions.  The standard
ones are inline and behave identically - and, unlike ours, are
constexpr where the standard requires it.  The custom
operator new(size_t, bool) overloads are not affected.
@bmwiedemann
bmwiedemann requested a review from a team as a code owner August 4, 2026 10:21
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.

1 participant