Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
werto87 opened this issue Jan 28, 2024 · 0 comments

Comments

@werto87
Copy link

werto87 commented Jan 28, 2024

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<st_tree::tree<int>, int>]’,
    inlined from ‘static void std::allocator_traits<std::allocator<_CharT> >::deallocate(allocator_type&, pointer, size_type) [with _Tp = st_tree::detail::node_raw<st_tree::tree<int>, int>]’ at /usr/include/c++/13.2.1/bits/alloc_traits.h:516:23,
    inlined from ‘void st_tree::tree<Data, CSModel, Alloc>::_delete_node(node_type*) [with Data = int; CSModel = st_tree::raw<>; Alloc = std::allocator<int>]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:296:63,
    inlined from ‘st_tree::detail::node_raw<Tree, Data>& st_tree::detail::node_raw<Tree, Data>::operator=(const st_tree::detail::node_raw<Tree, Data>&) [with Tree = st_tree::tree<int>; Data = int]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree_nodes.h:344:48,
    inlined from ‘st_tree::detail::node_raw<Tree, Data>::node_raw(const st_tree::detail::node_raw<Tree, Data>&) [with Tree = st_tree::tree<int>; 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<st_tree::tree<int>, int>; _Args = {const st_tree::detail::node_raw<st_tree::tree<int, st_tree::raw<st_tree::arg_unused>, std::allocator<int> >, int>&}; _Tp = st_tree::detail::node_raw<st_tree::tree<int>, int>]’ at /usr/include/c++/13.2.1/bits/new_allocator.h:187:4,
    inlined from ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = st_tree::detail::node_raw<st_tree::tree<int>, int>; _Args = {const st_tree::detail::node_raw<st_tree::tree<int, st_tree::raw<st_tree::arg_unused>, std::allocator<int> >, int>&}; _Tp = st_tree::detail::node_raw<st_tree::tree<int>, int>]’ at /usr/include/c++/13.2.1/bits/alloc_traits.h:537:17,
    inlined from ‘st_tree::tree<Data, CSModel, Alloc>::node_type* st_tree::tree<Data, CSModel, Alloc>::_new_node() [with Data = int; CSModel = st_tree::raw<>; Alloc = std::allocator<int>]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:290:62,
    inlined from ‘st_tree::detail::node_raw<Tree, Data>::node_type* st_tree::detail::node_raw<Tree, Data>::_copy_data(tree_type&) const [with Tree = st_tree::tree<int>; 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<int>::_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<Tree, Data>::node_type* st_tree::detail::node_raw<Tree, Data>::_copy_data(tree_type&) const [with Tree = st_tree::tree<int>; Data = int]’:
/home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:310:54: note: declared here
  310 | const typename tree<Data, CSModel, Alloc>::node_type tree<Data, CSModel, Alloc>::_node_init_val;
      |                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~
In member function ‘void std::__new_allocator<_Tp>::deallocate(_Tp*, size_type) [with _Tp = st_tree::detail::node_raw<st_tree::tree<int>, int>]’,
    inlined from ‘static void std::allocator_traits<std::allocator<_CharT> >::deallocate(allocator_type&, pointer, size_type) [with _Tp = st_tree::detail::node_raw<st_tree::tree<int>, int>]’ at /usr/include/c++/13.2.1/bits/alloc_traits.h:516:23,
    inlined from ‘void st_tree::tree<Data, CSModel, Alloc>::_delete_node(node_type*) [with Data = int; CSModel = st_tree::raw<>; Alloc = std::allocator<int>]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:296:63,
    inlined from ‘st_tree::detail::node_raw<Tree, Data>& st_tree::detail::node_raw<Tree, Data>::operator=(const st_tree::detail::node_raw<Tree, Data>&) [with Tree = st_tree::tree<int>; Data = int]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree_nodes.h:344:48,
    inlined from ‘st_tree::detail::node_raw<Tree, Data>::node_raw(const st_tree::detail::node_raw<Tree, Data>&) [with Tree = st_tree::tree<int>; 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<st_tree::tree<int>, int>; _Args = {const st_tree::detail::node_raw<st_tree::tree<int, st_tree::raw<st_tree::arg_unused>, std::allocator<int> >, int>&}; _Tp = st_tree::detail::node_raw<st_tree::tree<int>, int>]’ at /usr/include/c++/13.2.1/bits/new_allocator.h:187:4,
    inlined from ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = st_tree::detail::node_raw<st_tree::tree<int>, int>; _Args = {const st_tree::detail::node_raw<st_tree::tree<int, st_tree::raw<st_tree::arg_unused>, std::allocator<int> >, int>&}; _Tp = st_tree::detail::node_raw<st_tree::tree<int>, int>]’ at /usr/include/c++/13.2.1/bits/alloc_traits.h:537:17,
    inlined from ‘st_tree::tree<Data, CSModel, Alloc>::node_type* st_tree::tree<Data, CSModel, Alloc>::_new_node() [with Data = int; CSModel = st_tree::raw<>; Alloc = std::allocator<int>]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:290:62,
    inlined from ‘void st_tree::tree<Data, CSModel, Alloc>::emplace(Args&& ...) [with Args = {const int&}; Data = int; CSModel = st_tree::raw<>; Alloc = std::allocator<int>]’ at /home/walde/.conan2/p/st_trdd8863f0b6958/p/include/st_tree.h:194:26,
    inlined from ‘void st_tree::tree<Data, CSModel, Alloc>::insert(const data_type&) [with Data = int; CSModel = st_tree::raw<>; Alloc = std::allocator<int>]’ 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<int>::_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<Data, CSModel, Alloc>::node_type tree<Data, CSModel, Alloc>::_node_init_val;
      |                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant