https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94655
Bug ID: 94655 Summary: Implicit assignment operator triggers stringop-overflow warning Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: drahflow at gmx dot de Target Milestone: --- Running: g++-10 -O3 -W -Wall -Wextra -Werror --std=c++2a -c problem.c++ on this code: #include <functional> #include <memory> #include <string> struct A { std::string strA; // remove this line and it works char arr[16]; // remove this line and it works std::string strB; // remove this line and it works }; const A getA(); // remove "const" and it works void frob(const std::function<void()> &); struct B { int i; // remove this line and it works A data; B() { } void f(); }; void B::f() { frob([this]() { data = getA(); }); // data = getA(); // comment out the frob(...) and use this line, it works } results in: In member function ‘A& A::operator=(const A&)’, inlined from ‘B::f()::<lambda()>’ at problem.c++:26:17, inlined from ‘constexpr _Res std::__invoke_impl(std::__invoke_other, _Fn&&, _Args&& ...) [with _Res = void; _Fn = B::f()::<lambda()>&; _Args = {}]’ at /usr/include/c++/10/bits/invoke.h:60:36, inlined from ‘constexpr std::enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> std::__invoke_r(_Callable&&, _Args&& ...) [with _Res = void; _Callable = B::f()::<lambda()>&; _Args = {}]’ at /usr/include/c++/10/bits/invoke.h:110:28, inlined from ‘static _Res std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = void; _Functor = B::f()::<lambda()>; _ArgTypes = {}]’ at /usr/include/c++/10/bits/std_function.h:291:30: problem.c++:5:8: error: writing 16 bytes into a region of size 0 [-Werror=stringop-overflow=] 5 | struct A { | ^ problem.c++: In static member function ‘static _Res std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = void; _Functor = B::f()::<lambda()>; _ArgTypes = {}]’: problem.c++:6:15: note: at offset 0 to object ‘A::strA’ with size 32 declared here 6 | std::string strA; // remove this line and it works | ^~~~ Using instead -O2, it works. Using instead g++9, it works. % g++-10 --version g++-10 (Debian 10-20200222-1) 10.0.1 20200222 (experimental) [master revision 01af7e0a0c2:487fe13f218:e99b18cf7101f205bfdd9f0f29ed51caaec52779]