From 9e3e5cc386864d6679923d320bc573b77b05d28d Mon Sep 17 00:00:00 2001 From: Ben Baumgold Date: Tue, 20 Oct 2026 19:08:15 +0000 Subject: [PATCH] Keep dir_itr_imp::operator new/delete out of line to avoid -Wmismatched-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 #356. --- src/directory.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/directory.cpp b/src/directory.cpp index 42ff9922d..b3a504cd3 100644 --- a/src/directory.cpp +++ b/src/directory.cpp @@ -241,7 +241,11 @@ boost::scope::unique_fd openat_directory(int basedir_fd, path const& p, director BOOST_CONSTEXPR_OR_CONST std::size_t dir_itr_imp_extra_data_alignment = 16u; -BOOST_FILESYSTEM_DECL void* dir_itr_imp::operator new(std::size_t class_size, std::size_t extra_size) noexcept +// The class-specific operator new and operator delete are kept out of line as a pair. If GCC inlines only one of them +// into a caller, it sees malloc paired with free through the new/delete expressions and reports a false +// -Wmismatched-new-delete (an error with -Werror). + +BOOST_FILESYSTEM_DECL BOOST_NOINLINE void* dir_itr_imp::operator new(std::size_t class_size, std::size_t extra_size) noexcept { if (extra_size > 0) class_size = (class_size + dir_itr_imp_extra_data_alignment - 1u) & ~(dir_itr_imp_extra_data_alignment - 1u); @@ -254,12 +258,12 @@ BOOST_FILESYSTEM_DECL void* dir_itr_imp::operator new(std::size_t class_size, st return p; } -BOOST_FILESYSTEM_DECL void dir_itr_imp::operator delete(void* p, std::size_t extra_size) noexcept +BOOST_FILESYSTEM_DECL BOOST_NOINLINE void dir_itr_imp::operator delete(void* p, std::size_t extra_size) noexcept { std::free(p); } -BOOST_FILESYSTEM_DECL void dir_itr_imp::operator delete(void* p) noexcept +BOOST_FILESYSTEM_DECL BOOST_NOINLINE void dir_itr_imp::operator delete(void* p) noexcept { std::free(p); }