https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96188
Egor Suvorov <egor_suvorov at mail dot ru> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |egor_suvorov at mail dot ru --- Comment #4 from Egor Suvorov <egor_suvorov at mail dot ru> --- A possibly related example (also available at Godbolt: https://godbolt.org/z/P65dx1 ) At my Windows machine the following code #include <vector> int main() { struct S { // Defining the structure inside main is important. bool x = false; // Initialization is important. }; std::vector<S> v(3); // Can also be 2, 3, and 4, but not 0, 1, 5, or 6. v.emplace_back(S()); } yields following when compiled with g++ -O2 -Wextra: In member function 'void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {main()::S}; _Tp = main()::S; _Alloc = std::allocator<main()::S>]', inlined from 'int main()' at a.cpp:7:19: cc1plus.exe: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] In file included from C:/Software/msys64/mingw64/include/c++/10.2.0/x86_64-w64-mingw32/bits/c++allocator.h:33, from C:/Software/msys64/mingw64/include/c++/10.2.0/bits/allocator.h:46, from C:/Software/msys64/mingw64/include/c++/10.2.0/vector:64, from a.cpp:1: C:/Software/msys64/mingw64/include/c++/10.2.0/ext/new_allocator.h: In function 'int main()': C:/Software/msys64/mingw64/include/c++/10.2.0/ext/new_allocator.h:115:41: note: at offset 3 to an object with size 0 allocated by 'operator new' here 115 | return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ My g++ version is g++ (Rev6, Built by MSYS2 project) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.