From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A4D903858404; Fri, 9 Feb 2024 16:40:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4D903858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707496804; bh=McQE0J/mgGyz0A0Nu8GiILFiu1j8TyilEiNoFcv5udY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jhHZ2t4TIzg4Ceo3pFg61D+jL4XQjyHbHMZJnf7oH3Fa+r2BCp/X94jHIMFqzJh+3 cmiVQVvUxFgD24wN2zGq/AUi9TpCTFAgTYgPkT5oiWNFqN+tgrX8ku8dX7whSjNwD5 v6ia3yT+4Jq7SjyQnmrXo+7MLxD7L83FEGTDSyE8= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/113852] -Wsign-compare doesn't warn on unsigned result types Date: Fri, 09 Feb 2024 16:40:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: diagnostic 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: --- 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=3D113852 --- Comment #3 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #2) > I assume what's happening is that GCC assumes integer promotion from > uint16_t to int is value preserving and so we get two positive values, and > therefore comparison with an unsigned value is fine - there are no negati= ve > values involved and so it doesn't matter that we're comparing int with > unsigned long. But of course that's not true here. We have two positive i= nts > but their product overflows to produce a negative int. I guess we're also > assuming no overflow happens, because that would be undefined and we assu= me > no UB. Ah yes, if you add -fwrapv then you get the -Wsign-compare warning, because= now a negative product can occur without undefined overflow.=