https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120445
Bug ID: 120445 Summary: False -Wstringop-overread and -Wfree-nonheap-object positives Product: gcc Version: 15.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: christian.morales.vega at gmail dot com Target Milestone: --- Using this simple Boost.Json code ``` #include <boost/json/src.hpp> int main() { boost::json::value{{"Hello"}}; } ``` results in ``` $ g++ -g -O3 -flto -o /dev/null test.cpp -Iboost_1_88_0 In function 'relocate', inlined from 'reserve_impl' at boost_1_88_0/boost/json/impl/array.ipp:692:13, inlined from 'reserve' at boost_1_88_0/boost/json/impl/array.hpp:474:17, inlined from 'make_array' at boost_1_88_0/boost/json/impl/value_ref.ipp:149:16, inlined from 'make_value' at boost_1_88_0/boost/json/impl/value_ref.ipp:121:22, inlined from 'make_value' at boost_1_88_0/boost/json/impl/value_ref.ipp:95:26: boost_1_88_0/boost/json/impl/array.hpp:123:17: warning: 'memmove' reading between 24 and 103079215080 bytes from a region of size 0 [-Wstringop-overread] 123 | std::memmove( | ^ boost_1_88_0/boost/json/impl/array.ipp: In member function 'make_value': boost_1_88_0/boost/json/impl/array.ipp:31:14: note: at offset 8 into source object 'empty_' of size 8 31 | array::table array::empty_; | ^ In member function 'do_deallocate', inlined from 'deallocate' at boost_1_88_0/boost/container/pmr/memory_resource.hpp:54:33, inlined from 'deallocate' at boost_1_88_0/boost/json/impl/array.ipp:66:19, inlined from 'reserve_impl' at boost_1_88_0/boost/json/impl/array.ipp:698:22, inlined from 'reserve' at boost_1_88_0/boost/json/impl/array.hpp:474:17, inlined from 'make_array' at boost_1_88_0/boost/json/impl/value_ref.ipp:149:16, inlined from 'make_value' at boost_1_88_0/boost/json/impl/value_ref.ipp:121:22, inlined from 'make_value' at boost_1_88_0/boost/json/impl/value_ref.ipp:95:26: boost_1_88_0/boost/json/detail/impl/default_resource.ipp:53:22: warning: 'operator delete' called on unallocated object 'empty_' [-Wfree-nonheap-object] 53 | ::operator delete(p); | ^ boost_1_88_0/boost/json/impl/array.ipp: In member function 'make_value': boost_1_88_0/boost/json/impl/array.ipp:31:14: note: declared here 31 | array::table array::empty_; | ^ ``` AFAICT these are false positives. -Wstringop-overread complains about the memmove in https://github.com/boostorg/json/blob/develop/include/boost/json/impl/array.hpp#L123, but that's never called because just before there is a ``` if(n == 0) return; ``` and n is certainly 0, since it's initialized to that value in https://github.com/boostorg/json/blob/develop/include/boost/json/impl/value_ref.ipp#L148. -Wfree-nonheap-object complains about a delete that, again, is never called since there is a ``` if(p->capacity == 0) return; ``` in https://github.com/boostorg/json/blob/develop/include/boost/json/impl/array.ipp#L64