From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B6174385803C; Sat, 1 May 2021 02:36:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6174385803C From: "mrsam@courier-mta.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/100366] New: spurious warning - std::vector::clear followed by std::vector::insert(vec.end(), ...) with -O2 Date: Sat, 01 May 2021 02:36:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mrsam@courier-mta.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 May 2021 02:36:53 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100366 Bug ID: 100366 Summary: spurious warning - std::vector::clear followed by std::vector::insert(vec.end(), ...) with -O2 Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mrsam@courier-mta.com Target Milestone: --- I'm seeing this with both gcc 11.1 on: https://godbolt.org/z/1Wv9jj3r1 and gcc (GCC) 11.0.1 20210324 (Red Hat 11.0.1-0), below: Compiling the following with -O2 -Wall -Werror: #include #include static char UTC[4]; void func(std::vector &vec) { vec.clear(); vec.insert(vec.end(), UTC, UTC+4); } This generates a massive complaint that boils down to: /usr/include/c++/11/bits/stl_algobase.h:431:30: error: =E2=80=98void* __builtin_memcpy(v oid*, const void*, long unsigned int)=E2=80=99 writing 1 or more bytes into= a region of=20 size 0 overflows the destination [-Werror=3Dstringop-overflow=3D] 431 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num= ); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/11/x86_64-redhat-linux/bits/c++allocator. ...skipping 1 line from /usr/include/c++/11/bits/allocator.h:46, from /usr/include/c++/11/vector:64, from t.C:1: Removing vec.clear() makes this go away. Adding vec.reserve(4) after vec.clear() makes this go away.=