https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100485

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
-Wmismatched-new-delete considers only "mismatches between calls to operator
new or operator delete and the corresponding call to the allocation or
deallocation function."  It doesn't also consider attribute malloc, by design. 
It would be possible, even easy, to change that and have the warning also look
for attribute malloc to handle this case but it doesn't seem like a good design
feature to me to provide support for associating a member operator new() with
an unrelated deallocation function, whether it's free() or another operator
delete().  To do that, I would instead suggest suppressing the warning by using
#pragma GCC diagnostic ignored "-Wmismatched-new-delete":

extern "C" void free (void *);

class Base
{
public:
        Base();

        void * operator new(unsigned long, const int &);
        void operator delete(void * ptr, const int &) {
          #pragma GCC diagnostic ignored "-Wmismatched-new-delete"
          free (ptr);
        }
};

void f()
{
        new (0) Base;
}

Reply via email to