From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A0CFC385740D; Thu, 5 Aug 2021 15:56:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0CFC385740D From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/101791] New: missing warning on a mismatch between scalar and array forms of new and delete Date: Thu, 05 Aug 2021 15:56:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Aug 2021 15:56:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101791 Bug ID: 101791 Summary: missing warning on a mismatch between scalar and array forms of new and delete Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The -Wmismatched-new-delete warning introduced in GCC 11 is meant to diagno= se calls to operator delete with pointers obtained from a mismatched form or overload of operator new. A poster child for such a mismatch is the scalar form of a delete expression with an argument obtained from array new. GCC = 11 diagnoses such mismatches when they involve member operators new and delete= (as in g() below) but it fails to do the same for the default non-member operat= ors (as in h()). $ cat t.C && gcc -S -Wall t.Ctypedef __SIZE_TYPE__ size_t; struct A { void* operator new (size_t); void operator delete (void*); void* operator new[] (size_t); void operator delete[] (void*); }; void f (void*); void g () { A *p =3D new A[7]; f (p); delete p; // -Wmismatched-new-delete (good) } void h () { int *p =3D new int[7]; f (p); delete p; // missing warning } t.C: In function =E2=80=98void g()=E2=80=99: t.C:18:10: warning: =E2=80=98static void A::operator delete(void*)=E2=80=99= called on pointer returned from a mismatched allocation function [-Wmismatched-new-delete] 18 | delete p; // -Wmismatched-new-delete (good) | ^ t.C:16:17: note: returned from =E2=80=98static void* A::operator new [](siz= e_t)=E2=80=99 16 | A *p =3D new A[7]; | ^=