erikerlandson / st_tree

A fast and flexible c++ template class for tree data structures
https://github.com/erikerlandson/st_tree/wiki
Apache License 2.0
95 stars 20 forks source link

warning when compiling minimal example with "-Werror=free-nonheap-object -O3" #37

Open werto87 opened 7 months ago

werto87 commented 7 months ago

Compiling the following code with the "-Werror=free-nonheap-object -O3" flags leads to a warning

#include <st_tree.h>

using namespace st_tree;

int
main ()
{
  tree<int> t;
  t.insert(1);
  return 0;
}

how to reproduce:

  1. create a main.cxx file with the code from above.
  2. run "g++ main.cxx -I path/to/st_tree/include -O3 -Werror=free-nonheap-object"
log ``` In file included from /usr/include/c++/13.2.1/x86_64-pc-linux-gnu/bits/c++allocator.h:33, from /usr/include/c++/13.2.1/bits/allocator.h:46, from /usr/include/c++/13.2.1/string:43, from /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:25, from main.cxx:1: In member function ‘void std::__new_allocator<_Tp>::deallocate(_Tp*, size_type) [with _Tp = st_tree::detail::node_raw, int>]’, inlined from ‘static void std::allocator_traits >::deallocate(allocator_type&, pointer, size_type) [with _Tp = st_tree::detail::node_raw, int>]’ at /usr/include/c++/13.2.1/bits/alloc_traits.h:516:23, inlined from ‘void st_tree::tree::_delete_node(node_type*) [with Data = int; CSModel = st_tree::raw<>; Alloc = std::allocator]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:296:63, inlined from ‘st_tree::detail::node_raw& st_tree::detail::node_raw::operator=(const st_tree::detail::node_raw&) [with Tree = st_tree::tree; Data = int]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree_nodes.h:344:48, inlined from ‘st_tree::detail::node_raw::node_raw(const st_tree::detail::node_raw&) [with Tree = st_tree::tree; Data = int]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree_nodes.h:302:15, inlined from ‘void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = st_tree::detail::node_raw, int>; _Args = {const st_tree::detail::node_raw, std::allocator >, int>&}; _Tp = st_tree::detail::node_raw, int>]’ at /usr/include/c++/13.2.1/bits/new_allocator.h:187:4, inlined from ‘static void std::allocator_traits >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = st_tree::detail::node_raw, int>; _Args = {const st_tree::detail::node_raw, std::allocator >, int>&}; _Tp = st_tree::detail::node_raw, int>]’ at /usr/include/c++/13.2.1/bits/alloc_traits.h:537:17, inlined from ‘st_tree::tree::node_type* st_tree::tree::_new_node() [with Data = int; CSModel = st_tree::raw<>; Alloc = std::allocator]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:290:62, inlined from ‘st_tree::detail::node_raw::node_type* st_tree::detail::node_raw::_copy_data(tree_type&) const [with Tree = st_tree::tree; Data = int]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree_nodes.h:465:39: /usr/include/c++/13.2.1/bits/new_allocator.h:168:33: error: ‘void operator delete(void*, std::size_t)’ called on unallocated object ‘st_tree::tree::_node_init_val’ [-Werror=free-nonheap-object] 168 | _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n)); | ^ /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h: In function ‘st_tree::detail::node_raw::node_type* st_tree::detail::node_raw::_copy_data(tree_type&) const [with Tree = st_tree::tree; Data = int]’: /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:310:54: note: declared here 310 | const typename tree::node_type tree::_node_init_val; | ^~~~~~~~~~~~~~~~~~~~~~~~~~ In member function ‘void std::__new_allocator<_Tp>::deallocate(_Tp*, size_type) [with _Tp = st_tree::detail::node_raw, int>]’, inlined from ‘static void std::allocator_traits >::deallocate(allocator_type&, pointer, size_type) [with _Tp = st_tree::detail::node_raw, int>]’ at /usr/include/c++/13.2.1/bits/alloc_traits.h:516:23, inlined from ‘void st_tree::tree::_delete_node(node_type*) [with Data = int; CSModel = st_tree::raw<>; Alloc = std::allocator]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:296:63, inlined from ‘st_tree::detail::node_raw& st_tree::detail::node_raw::operator=(const st_tree::detail::node_raw&) [with Tree = st_tree::tree; Data = int]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree_nodes.h:344:48, inlined from ‘st_tree::detail::node_raw::node_raw(const st_tree::detail::node_raw&) [with Tree = st_tree::tree; Data = int]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree_nodes.h:302:15, inlined from ‘void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = st_tree::detail::node_raw, int>; _Args = {const st_tree::detail::node_raw, std::allocator >, int>&}; _Tp = st_tree::detail::node_raw, int>]’ at /usr/include/c++/13.2.1/bits/new_allocator.h:187:4, inlined from ‘static void std::allocator_traits >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = st_tree::detail::node_raw, int>; _Args = {const st_tree::detail::node_raw, std::allocator >, int>&}; _Tp = st_tree::detail::node_raw, int>]’ at /usr/include/c++/13.2.1/bits/alloc_traits.h:537:17, inlined from ‘st_tree::tree::node_type* st_tree::tree::_new_node() [with Data = int; CSModel = st_tree::raw<>; Alloc = std::allocator]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:290:62, inlined from ‘void st_tree::tree::emplace(Args&& ...) [with Args = {const int&}; Data = int; CSModel = st_tree::raw<>; Alloc = std::allocator]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:194:26, inlined from ‘void st_tree::tree::insert(const data_type&) [with Data = int; CSModel = st_tree::raw<>; Alloc = std::allocator]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:200:49, inlined from ‘int main()’ at main.cxx:9:11: /usr/include/c++/13.2.1/bits/new_allocator.h:168:33: error: ‘void operator delete(void*, std::size_t)’ called on unallocated object ‘st_tree::tree::_node_init_val’ [-Werror=free-nonheap-object] 168 | _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n)); | ^ /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h: In function ‘int main()’: /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:310:54: note: declared here 310 | const typename tree::node_type tree::_node_init_val; | ^~~~~~~~~~~~~~~~~~~~~~~~~~ cc1plus: some warnings being treated as errors ```