https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107694
Bug ID: 107694 Summary: Bogus stringop-overflow warning in gcc 12 Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: mh+gcc at glandium dot org Target Milestone: --- Reproducer: ``` #include <atomic> class nsISupports { public: virtual int Release(); }; struct JSPrincipals { std::atomic<int> refcount; }; class nsJSPrincipals : nsISupports, JSPrincipals { static nsJSPrincipals* get(JSPrincipals* principals) { return static_cast<nsJSPrincipals*>(principals); } void Destroy(JSPrincipals* jsprin); }; void nsJSPrincipals::Destroy(JSPrincipals* jsprin) { nsJSPrincipals* nsjsprin = nsJSPrincipals::get(jsprin); nsjsprin->refcount.fetch_add(1, std::memory_order_acq_rel); nsjsprin->Release(); } ``` Compile with: g++ -c -O2 -Werror=stringop-overflow It says: ``` In file included from /builds/worker/fetches/gcc/include/c++/12.2.0/atomic:41, from Unified_cpp_caps0.ii.cpp:1: In member function 'std::__atomic_base<_IntTp>::__int_type std::__atomic_base<_IntTp>::fetch_add(__int_type, std::memory_order) [with _ITp = int]', inlined from 'void nsJSPrincipals::Destroy(JSPrincipals*)' at Unified_cpp_caps0.ii.cpp:19:30: /builds/worker/fetches/gcc/include/c++/12.2.0/bits/atomic_base.h:618:34: error: 'unsigned int __atomic_fetch_add_4(volatile void*, unsigned int, int)' writing 4 bytes into a region of size 0 overflows the destination [-Werror=stringop-overflow=] 618 | { return __atomic_fetch_add(&_M_i, __i, int(__m)); } | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ cc1plus: some warnings being treated as errors ```