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

            Bug ID: 122061
           Summary: Wmismatched-new-delete extension
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

Recent gcc trunk can find two problems in this code:

struct S
{
    S();
    ~S();
    char * p1;
    char * p2;
};

void f()
{
    S * q1 = new S;
    S * q2 = new S [ 10];

    delete [] q1;
    delete q2;
}

$ ~/gcc/results/bin/g++ -c -g -O2 -Wall -Wextra -pedantic -fhardened sep25c.cc
...
sep25c.cc:15:19: warning: ‘void operator delete [](void*, long unsigned int)’
called on pointer returned from a mismatched allocation function
[-Wmismatched-new-delete]
sep25c.cc:16:16: warning: ‘void operator delete(void*, long unsigned int)’
called on pointer returned from a mismatched allocation function
[-Wmismatched-new-delete]

but can't find a problem with this:

struct S
{
    S();
    ~S();
    char * p1;
    char * p2;
};

S::S()
{
    p1 = new char [ 10];
    p2 = new char;
};

S::~S()
{
    delete p1;
    delete [] p2;
}

Reply via email to