Skip to content

Build failure with gcc >= 15.2: -Wmismatched-new-delete false positive in generator_test.cc (sanitize mode) #3422

@travisdowns

Description

@travisdowns

Summary

Building tests/unit/generator_test.cc in sanitize mode (-Werror enabled) with gcc 15.2 fails with a -Wmismatched-new-delete diagnostic raised inside libstdc++'s <generator> header. The same source compiles cleanly with earlier gcc-15 snapshots (e.g. a pre-15.1 trunk from April 2025) — only the compiler changed.

Reproducer

Fedora 42 ships gcc 15.2.1-7, which reliably reproduces:

docker run --rm -v /path/to/seastar:/seastar -w /seastar fedora:42 bash -c '
  dnf install -y gcc gcc-c++ cmake ninja-build ragel doxygen \
    boost-devel c-ares-devel fmt-devel gnutls-devel hwloc-devel \
    libpciaccess-devel libtool liburing-devel libxml2-devel \
    lksctp-tools-devel lz4-devel make meson numactl-devel \
    openssl openssl-devel protobuf-compiler protobuf-devel \
    python3 python3-pyelftools python3-pyyaml stow \
    systemtap-sdt-devel valgrind-devel xfsprogs-devel yaml-cpp-devel \
    libasan libubsan libatomic diffutils which &&
  ./configure.py --mode=sanitize &&
  ninja -C build/sanitize tests/unit/CMakeFiles/test_unit_generator.dir/generator_test.cc.o
'

This was also seen in CI at https://github.com/scylladb/seastar/actions/runs/26201469110/job/77092176645?pr=3412.

Error

tests/unit/generator_test.cc: In function 'sync_generator<int> sync_fibonacci_sequence(unsigned int)':
tests/unit/generator_test.cc:49:1: error: 'static void std::__gen::_Promise_alloc<void>::operator delete(void*, std::size_t)' called on pointer returned from a mismatched allocation function [-Werror=mismatched-new-delete]
   49 | sync_fibonacci_sequence(unsigned count) {
      | ^~~~~~~~~~~~~~~~~~~~~~~
In static member function 'static void* std::__gen::_Promise_alloc<void>::operator new(std::size_t)',
    inlined from 'sync_generator<int> sync_fibonacci_sequence(unsigned int)' at tests/unit/generator_test.cc:49:1:
/usr/include/c++/15/generator:617:36: note: returned from 'void* operator new(std::size_t)'
  617 |           auto __p = ::operator new(__nsz);
      |                      ~~~~~~~~~~~~~~^~~~~~~
cc1plus: all warnings being treated as errors

Analysis

The diagnostic fires at sync_fibonacci_sequence because that's the only std::generator coroutine in this TU (selected by the #if __cplusplus >= 202302L && defined(__cpp_lib_generator) branch in generator_test.cc).

The pointed-at libstdc++ code pairs the unsized global ::operator new(size_t) (in _Promise_alloc<void>::operator new) with a sized _Promise_alloc<void>::operator delete(void*, size_t). After inlining, gcc 15.2's -Wmismatched-new-delete reports this pair as mismatched. The libstdc++ <generator> header itself is byte-identical between the two gcc snapshots tested — only the compiler diagnostic changed — and pairing unsized ::operator new with sized ::operator delete is well-formed per the C++ standard (sized delete was specifically added in C++14 to coexist with unsized new).

This is a known gcc false positive:

  • gcc PR middle-end/109224-Wmismatched-new-delete false positive with a templated operator new (common with coroutines). Classified as a middle-end issue, not a libstdc++ defect. Open as of late 2025.

The same diagnostic also trips libstdc++'s own test (24_iterators/range_generators/01.cc), so seastar isn't doing anything unusual — any std::generator coroutine compiled with -Werror -Wall under affected gcc versions hits this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions