public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-100861-4-kZH7MyN5t2@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-100861-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100861 Martin Sebor <msebor at gcc dot gnu.org> 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 <msebor at gcc dot gnu.org> --- 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 delete. Alternatively, if Widget defines a non-inline member operator new() that also prevents the warning because calls to both operators match. With that, I'm not sure that suppressing the warning for a destroying operator 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 other 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 delete. 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=100406 [Bug 100406] bogus/missing -Wmismatched-new-delete
next prev parent reply other threads:[~2021-06-01 21:36 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-01 19:43 [Bug c++/100861] New: " josephcsible at gmail dot com 2021-06-01 21:36 ` msebor at gcc dot gnu.org [this message] 2021-06-01 21:49 ` [Bug middle-end/100861] " josephcsible at gmail dot com 2021-06-01 22:08 ` msebor at gcc dot gnu.org 2023-12-22 18:31 ` pinskia at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-100861-4-kZH7MyN5t2@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).