From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C12513858C54; Wed, 26 Jul 2023 12:04:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C12513858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690373042; bh=UVCXU4cHzmj7eFoyz0cXrZIpml1udkP4ShnT04xjeLA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WksfH96RtS1AH+yBVb96uIwZ6hwXnySfpwSuTW+X6wqMbZsWmYHl//55u/82wLoLJ tIOzhlZ9qNMHMr+tbTTJGHmpuOPH5Cp5e+wEU8LRW2ovfZePvz1mqSwup+FbPwMa/e iFWXECH6vuoKa9OmwrVENb1+sGEGULUDz/mwvcw8= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/110807] [13/14 Regression] Copy list initialisation of a vector raises a warning with -O2 Date: Wed, 26 Jul 2023 12:04:02 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.2 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110807 --- Comment #3 from Jonathan Wakely --- I think this is the same warning that causes libstdc++ testsuite failures w= hen testing with --target_board=3Dunix/-D_GLIBCXX_DEBUG FAIL: 23_containers/vector/bool/swap.cc (test for excess errors) I thought I'd already reported that, but I can't find it. The library allocates space for N elements then copies n elements: vector(const vector& __x) : _Base(_Bit_alloc_traits::_S_select_on_copy(__x._M_get_Bit_allocator= ())) { _M_initialize(__x.size()); _M_copy_aligned(__x.begin(), __x.end(), begin()); } We probably have the usual problem that GCC thinks allocating memory might alter __x because it's a global, and so in theory (but never in practice) t= he program could replace operator new with something insane that modifies the global. I tried changing the constructor to: const_iterator __xbegin =3D __x.begin(), __xend =3D __x.end(); _M_initialize(__x.size()); _M_copy_aligned(__xbegin, __xend, begin()); That fixes the library test FAILs, but not the case in this bug report.=