From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CE28C3874C28; Fri, 5 Mar 2021 12:55:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE28C3874C28 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/99402] [10/11 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator Date: Fri, 05 Mar 2021 12:55:58 +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: 10.2.0 X-Bugzilla-Keywords: 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: 10.3 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 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: Fri, 05 Mar 2021 12:55:58 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99402 --- Comment #5 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #3) > You should be using __base_dist.second, no? No, it's not that simple. I don't understand how this code is meant to work, but this can't be right: if (this->_M_is_begin()) { if (__rhs._M_is_before_begin()) return std::make_pair(-1, __dp_exact); if (__rhs._M_is_end()) return __seq_dist; return std::make_pair(__seq_dist.first, __seq_dist.second =3D=3D __dp_exact ? __dp_sign_max_size : __seq_dist.second); } We can't use __seq_dist.first as the distance, because we have already established that __rhs is not the end iterator, so it must be before the en= d. And so the distance we're trying to find must be less than __seq_dist.first= .=