From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7649B389365C; Fri, 24 Apr 2020 19:59:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7649B389365C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587758368; bh=5eQ4r/c/yqQtqDjc2O1MGeKvbroc/d6uotBWit9UwQ8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ukTLLgVQMCLMCSHzWA7EUIlDHFLVE26637BC82rrl+GWAxGi7b+L4YO3RxN8gu6Rn AX8UIrVAQfa2R7cM8FA31Vc/0sZLsIoBOo0FWt6qVLuWCMqeqDwjlWTVdM3HkdCg0T IWlRrVzoKruCFl0KGqb87zYuhDttoCQZj8O4fNgU= From: "nathan at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/94747] Confusing code in libsupc++/dyncast.cc Date: Fri, 24 Apr 2020 19:59:28 +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: 7.5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nathan at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: nathan at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cf_reconfirmed_on short_desc cc bug_status assigned_to resolution everconfirmed 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, 24 Apr 2020 19:59:28 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94747 Nathan Sidwell changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2020-04-24 Summary|Undefined behavior: integer |Confusing code in |overflow in |libsupc++/dyncast.cc |libsupc++/dyncast.cc | CC| |nathan at gcc dot gnu.org Status|RESOLVED |ASSIGNED Assignee|unassigned at gcc dot gnu.org |nathan at gcc dot g= nu.org Resolution|INVALID |--- Ever confirmed|0 |1 --- Comment #3 from Nathan Sidwell --- While the code is well formed, it does not convey intent well. I wrote that code, and probably even considered spelling as -ptrdiff_t (offsetof ...). b= ut didn't because it causes a line wrap and has no semantic difference. negating unsigned numbers often shows programmer confusion, and can cause b= ugs on I32LP64 systems, where the negation happens at a lower precision than expected.=20=20 That's not the case here. If size_t has fewer bits than a pointer, there ca= nnot be overflow from the top size_t bit to the pointer arithmetic -- that break= s C & C++ semantics. Something for stage 1=