From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E06A8385780B; Tue, 1 Jun 2021 21:36:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E06A8385780B From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/100861] False positive -Wmismatched-new-delete with destroying operator delete Date: Tue, 01 Jun 2021 21:36:03 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: NEW 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_severity bug_status component cf_reconfirmed_on cc everconfirmed blocked Message-ID: In-Reply-To: References: 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: Tue, 01 Jun 2021 21:36:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100861 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement Status|UNCONFIRMED |NEW Component|c++ |middle-end Last reconfirmed| |2021-06-01 CC| |msebor at gcc dot gnu.org Ever confirmed|0 |1 Blocks| |100406 --- Comment #1 from Martin Sebor --- The warning doesn't do anything special with destroying operator delete or = any other kinds of the operators (other than scalar vs array). It triggers for this test case because it sees the result of ::operator new() being passed = to Widget::operator delete (Widget*). If Widget::operator delete() is inlined (e.g., declared with attribute always_inline) the warning goes away just as long as the operator doesn't pass the pointer to the wrong overload of dele= te.=20 Alternatively, if Widget defines a non-inline member operator new() that al= so prevents the warning because calls to both operators match. With that, I'm not sure that suppressing the warning for a destroying opera= tor delete() would be a good solution. It seems to me that the right fix is to solve the broader problem where one of the operators is inlined and the oth= er isn't (similar to pr100485, except with the definitions of both operators available in the same translation unit). Until/unless a solution is developed I would suggest to either define the destroying operator delete inline and have it call an out-of-line function = to do the work (as shown below) or to force the inlining of the destroying del= ete. struct Widget { const WidgetKind Kind : 4; unsigned OtherThings : 28; Widget(WidgetKind k) : Kind(k) {} void operator delete(Widget *widget, std::destroying_delete_t) { destroy_delete (widget); } static __attribute__ ((noinline)) void destroy_delete (Widget *); }; Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100406 [Bug 100406] bogus/missing -Wmismatched-new-delete=