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};
      |       ^~~

Reply via email to