From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5E7833858C2C; Wed, 3 Jan 2024 10:16:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E7833858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704276965; bh=9os0vM/C1C7Lk4SR2FaEGu96qPJRqS745Yu5GMqr0bk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Aq4VKyV/9Hom1ohzRWBqjLLGB5OQ1cu1anoRdTYfQ/18BVIczqrNmLzYfPX0PbNz1 nwJ4tf96gsjQ/Ey2wyuZUJpuDWRpXtbdxno6iA6DcBa4JlgZkcwgpZewXgd8489DE2 FyXxPi+0Sh4FICb1OMOOPUq3R+4hsk5vLM1DOsnE= From: "xry111 at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/113202] std::find does not work with the maximum range of pointers Date: Wed, 03 Jan 2024 10:16:03 +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.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: xry111 at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: 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=3D113202 --- Comment #9 from Xi Ruoyao --- (In reply to Carsten Schmidt from comment #6) > > Why do you think this is a bug? >=20 > 1. Considering the "possible implementation" of cppreference.com, pointer > arithmetic, e.g. ptr-ptr, should not be an issue when searching for the > sentinel. Quoting from https://en.cppreference.com/w/cpp/iterator: An iterator j is called reachable from an iterator i if and only if there i= s a finite sequence of applications of the expression ++i that makes i =3D=3D j= . If j is reachable from i, they refer to elements of the same sequence. A range is a pair of iterators that designate the beginning and end of the computation. A range [i, i) is an empty range; in general, a range [i, j) refers to the elements in the data structure starting with the element poin= ted to by i and up to but not including the element pointed to by j. Range [i, j) is valid if and only if j is reachable from i. Here there is no finite sequences of applications of the expression ++i that makes i =3D=3D j because running ++i will invoke undefined behavior far bef= ore i =3D=3D j. Thus this range is invalid. And: The result of the application of functions in the standard library to inval= id ranges is undefined. =