Repository navigation
Conversation
baumgold
force-pushed
the
fix-gcc-mismatched-new-delete
branch
from
October 20, 2026 17:40
bf6887f to
c6f3fd7
Compare
…ed-new-delete dir_itr_imp::operator new allocates with std::malloc and operator delete releases with std::free, which is correct. GCC reports -Wmismatched-new-delete when it inlines only one half of the pair into a caller, which breaks -Werror builds (e.g. GCC 15 at -O1). Mark the operator new and both operator delete overloads BOOST_NOINLINE so the pair is treated consistently, as suggested in GCC PR 103993. Fixes boostorg#356.
baumgold
force-pushed
the
fix-gcc-mismatched-new-delete
branch
from
October 20, 2026 19:08
c6f3fd7 to
9e3e5cc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #356.
dir_itr_imp::operator newallocates withstd::mallocandoperator deletereleases withstd::free, which is correct. GCC reports-Wmismatched-new-deletewhen it inlines only one half of such a pair into a caller (the diagnostic is computed on the optimized code), so with-Werrorthis fails e.g. with GCC 15 at-O1. This is a known GCC limitation, see GCC PR 103993, where the suggested workaround is to keep the allocation and deallocation functions both inlined or both out of line.This marks
operator newand bothoperator deleteoverloadsBOOST_NOINLINE. There is no diagnostic pragma and no change to how memory is allocated or freed. It costs one non-inlined call per directory open.Testing (GCC 15.2.0, AlmaLinux 9, x86-64):
libs/filesystem/src/directory.cppondevelopwith-Wall -Werror -fsanitize=thread: unpatched fails with-Werror=mismatched-new-deleteat-O1; patched compiles cleanly at-Og,-O1,-O2and-Os(C++20 and C++26).b2 libs/filesystem/test, GCC 15,-O1 -Wall -Werror=mismatched-new-delete, C++20) builds and passes with the patch (32 passed, 0 failed).b2build of the filesystem library did not reproduce the error on unpatcheddevelopin my setup, so the single-file compile above is the evidence that the change removes the diagnostic.-O1 -fsanitize=threadbuild of a large project that failed on this error now builds, and its tests pass.🤖 Generated with Claude Code