https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108860
Alexandre Duret-Lutz <adl at gnu dot org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |adl at gnu dot org --- Comment #3 from Alexandre Duret-Lutz <adl at gnu dot org> --- Arrived here because I have the same issue, but with an even simpler input. % cat foo.c #include <vector> void test(std::vector<int>& v) { v.insert(v.begin(), 12); } % g++ -O -std=c++20 -Werror=null-dereference -c foo.cc In file included from /usr/include/c++/13/bits/stl_iterator.h:85, from /usr/include/c++/13/bits/stl_algobase.h:67, from /usr/include/c++/13/vector:62, from foo.cc:1: In function ‘constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*, _Args&& ...) [with _Tp = int; _Args = {int}]’, inlined from ‘static constexpr void std::allocator_traits<std::allocator<_Up> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = int; _Args = {int}; _Tp = int]’ at /usr/include/c++/13/bits/alloc_traits.h:540:21, inlined from ‘constexpr void std::vector<_Tp, _Alloc>::_M_realloc_insert(iterator, _Args&& ...) [with _Args = {int}; _Tp = int; _Alloc = std::allocator<int>]’ at /usr/include/c++/13/bits/vector.tcc:468:28, inlined from ‘constexpr std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::_M_insert_rval(const_iterator, value_type&&) [with _Tp = int; _Alloc = std::allocator<int>]’ at /usr/include/c++/13/bits/vector.tcc:372:19, inlined from ‘constexpr std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, value_type&&) [with _Tp = int; _Alloc = std::allocator<int>]’ at /usr/include/c++/13/bits/stl_vector.h:1394:30, inlined from ‘void test(std::vector<int>&)’ at foo.cc:5:11: /usr/include/c++/13/bits/stl_construct.h:97:14: error: potential null pointer dereference [-Werror=null-dereference] 97 | { return ::new((void*)__location) _Tp(std::forward<_Args>(__args)...); } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1plus: some warnings being treated as errors Reproduced with - g++-13 (Debian 13.2.0-25) 13.2.0 - g++-12 (Debian 12.3.0-17) 12.3.0