https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118867
Bug ID: 118867
Summary: [15 regression] -Wfree-nonheap-object false positive
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: snyder at bnl dot gov
Target Milestone: ---
hi -
(Refiled from bug 118865 as requested.)
This test case generates a false-positive -Wfree-nonheap-object warning
with gcc 15 -O1 (tested as of 20250213 on a fedora 40 x86_64 system):
-- test2.cc ------------------------------------------------------------
#include <list>
#include <cmath>
void foo(double);
double dist (int, int);
void processJetContainer(const int* jbeg, const int* jend,
const int* rbeg, const int* rend)
{
using lint = std::list<int>;
if (jbeg == jend) return;
lint listJets(jbeg, jend);
for (; rbeg < rend; ++rbeg)
{
double dr2min = 500000;
if (listJets.empty() ) break;
lint::iterator it=listJets.begin();
lint::iterator itmin=it;
for( ; it != listJets.end(); ++it) {
double dr2 = dist(*it, *rbeg);
if(dr2 < dr2min) { dr2min = dr2; itmin = it ;}
}
listJets.erase(itmin);
foo (sqrt(dr2min));
}
}
------------------------------------------------------------------------
$ g++ -c -O1 test2.cc
In file included from
/usr/local/gcc/include/c++/15.0.1/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
from /usr/local/gcc/include/c++/15.0.1/bits/allocator.h:46,
from /usr/local/gcc/include/c++/15.0.1/list:65,
from test2.cc:1:
In member function ‘void std::__new_allocator<_Tp>::deallocate(_Tp*, size_type)
[with _Tp = std::_List_node<int>]’,
inlined from ‘static void std::allocator_traits<std::allocator<_Tp1>
>::deallocate(allocator_type&, pointer, size_type) [with _Tp =
std::_List_node<int>]’ at
/usr/local/gcc/include/c++/15.0.1/bits/alloc_traits.h:649:23,
inlined from ‘void std::__cxx11::_List_base<_Tp,
_Alloc>::_M_put_node(_Node_ptr) [with _Tp = int; _Alloc = std::allocator<int>]’
at /usr/local/gcc/include/c++/15.0.1/bits/stl_list.h:820:32,
inlined from ‘void std::__cxx11::_List_base<_Tp,
_Alloc>::_M_destroy_node(_Node_ptr) [with _Tp = int; _Alloc =
std::allocator<int>]’ at
/usr/local/gcc/include/c++/15.0.1/bits/stl_list.h:855:19,
inlined from ‘void std::__cxx11::list<_Tp, _Allocator>::_M_erase(iterator)
[with _Tp = int; _Alloc = std::allocator<int>]’ at
/usr/local/gcc/include/c++/15.0.1/bits/stl_list.h:2485:23,
inlined from ‘std::__cxx11::list<_Tp, _Allocator>::iterator
std::__cxx11::list<_Tp, _Allocator>::erase(const_iterator) [with _Tp = int;
_Alloc = std::allocator<int>]’ at
/usr/local/gcc/include/c++/15.0.1/bits/list.tcc:153:15,
inlined from ‘void processJetContainer(const int*, const int*, const int*,
const int*)’ at test2.cc:27:19:
/usr/local/gcc/include/c++/15.0.1/bits/new_allocator.h:172:66: warning: ‘void
operator delete(void*, std::size_t)’ called on unallocated object ‘listJets’
[-Wfree-nonheap-object]
172 | _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
| ^
test2.cc: In function ‘void processJetContainer(const int*, const int*, const
int*, const int*)’:
test2.cc:13:8: note: declared here
13 | lint listJets(jbeg, jend);
| ^~~~~~~~
$
No warning is observed with gcc 14.2.1.