https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103993
cdfrey at foursquare dot net changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |cdfrey at foursquare dot net --- Comment #5 from cdfrey at foursquare dot net --- This happens for me. Here is a test case, for gcc 13.1.0, which gives the warning with this command: /home/gcc/rootdir/gcc-13.1.0/bin/g++ -Wall -O2 --std=c++17 -Wall -Wextra -Werror -fmax-errors=4 -c -o gcc-test-case.o gcc-test-case.cc gcc-test-case.cc: In function ‘int main()’: gcc-test-case.cc:49:16: error: ‘static void Test::operator delete(void*)’ called on pointer returned from a mismatched allocation function [-Werror=mismatched-new-delete] 49 | delete t; | ^ In static member function ‘static void* Test::operator new(size_t)’, inlined from ‘int main()’ at gcc-test-case.cc:48:10: gcc-test-case.cc:17:30: note: returned from ‘void* malloc(size_t)’ 17 | return malloc(size); | ~~~~~~^~~~~~ gcc-test-case.cc: In function ‘int main()’: gcc-test-case.cc:48:17: error: ‘static void Test::operator delete(void*)’ called on pointer returned from a mismatched allocation function [-Werror=mismatched-new-delete] 48 | t = new Test; | ^~~~ In static member function ‘static void* Test::operator new(size_t)’, inlined from ‘int main()’ at gcc-test-case.cc:48:10: gcc-test-case.cc:17:30: note: returned from ‘void* malloc(size_t)’ 17 | return malloc(size); | ~~~~~~^~~~~~ cc1plus: all warnings being treated as errors make: *** [<builtin>: gcc-test-case.o] Error 1 The code: #include <iostream> // cout statements needed to trigger warning #include <new> #include <stdlib.h> using namespace std; struct Test { double a, b, c; Test() { cout << "Test::Test()\n"; } void* operator new(size_t size) { cout << "Test::operator new(" << size << ")\n"; return malloc(size); } void* operator new(size_t size, align_val_t al) { cout << "Test::operator new(" << size << ", align: " << (size_t)al << ")\n"; return aligned_alloc((size_t)al, size); } void* operator new(size_t size, const std::nothrow_t &) throw() { cout << "Test::operator new(" << size << ", nothrow)\n"; return malloc(size); } void operator delete(void *p) { cout << "Test::operator delete()\n"; free(p); } void operator delete(void *p, align_val_t al) { cout << "Test::operator delete(p, align: " << (size_t)al << ")\n"; free(p); } }; int main(void) { Test *t; t = new Test; delete t; }