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 c++/57111] Generalize -Wfree-nonheap-object to delete
Date: Thu, 05 Nov 2020 17:52:55 +0000	[thread overview]
Message-ID: <bug-57111-4-HiRy4w0RiS@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-57111-4@http.gcc.gnu.org/bugzilla/>

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
                 CC|                            |msebor at gcc dot gnu.org
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=90629

--- Comment #11 from Martin Sebor <msebor at gcc dot gnu.org> ---
The patch I submitted for pr90629 implements this enhancement:
https://gcc.gnu.org/pipermail/gcc-patches/2020-November/557987.html

It detects the bug in the test case in comment #0 but only with optimization
(to see through inlined calls) and with -Wsystem-headers.  Just like all late
warnings to date, -Wfree-nonheap-object isn't without false positives.  pr54202
is one that even the exceedingly simplistic -Wfree-nonheap-object is
susceptible to.  The patch above doesn't change things.

In file included from
/build/gcc-trunk/x86_64-pc-linux-gnu/libstdc++-v3/include/memory:76,
                 from t.C:2:
In member function ‘typename std::enable_if<std::is_convertible<_Up (*)[], _Tp
(*)[]>::value>::type std::default_delete<_Tp []>::operator()(_Up*) const [with
_Up = int; _Tp = int]’,
    inlined from ‘std::unique_ptr<_Tp [], _Dp>::~unique_ptr() [with _Tp = int;
_Dp = std::default_delete<int []>]’ at
/build/gcc-trunk/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/unique_ptr.h:612:17,
    inlined from ‘int main()’ at t.C:6:32:
/build/gcc-trunk/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/unique_ptr.h:120:11:
warning: ‘void operator delete [](void*)’ called on unallocated object ‘arr’
[-Wfree-nonheap-object]
  120 |           delete [] __ptr;
      |           ^~~~~~~~~~~~~~~
t.C: In function ‘int main()’:
t.C:5:7: note: declared here
    5 |   int arr[]={1,2};
      |       ^~~

  parent reply	other threads:[~2020-11-05 17:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
2013-04-29 12:57 ` [Bug c++/57111] " redi at gcc dot gnu.org
2013-04-29 14:04 ` jb.1234abcd at gmail dot com
2013-04-29 14:09 ` redi at gcc dot gnu.org
2013-04-30 18:37 ` glisse at gcc dot gnu.org
2013-04-30 21:57 ` jb.1234abcd at gmail dot com
2013-04-30 22:07 ` glisse at gcc dot gnu.org
2013-04-30 22:22 ` jb.1234abcd at gmail dot com
2013-04-30 22:58 ` [Bug c++/57111] Generalize -Wfree-nonheap-object to delete glisse at gcc dot gnu.org
2013-04-30 23:01 ` redi at gcc dot gnu.org
2020-11-05 17:52 ` msebor at gcc dot gnu.org [this message]
2020-11-09 14:51 ` redi at gcc dot gnu.org
2020-12-03 22:56 ` msebor at gcc dot gnu.org
2020-12-08 20:51 ` msebor at gcc dot gnu.org
2020-12-14 20:31 ` cvs-commit at gcc dot gnu.org
2020-12-14 20:34 ` msebor at gcc dot gnu.org
2021-01-10 23:21 ` cvs-commit at gcc dot gnu.org
2023-06-14  9:43 ` cvs-commit at gcc dot gnu.org
2023-06-15  7:21 ` cvs-commit 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-57111-4-HiRy4w0RiS@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: link
Be 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).