From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EE6143858D39; Fri, 11 Mar 2022 00:22:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE6143858D39 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/104875] libstdc++-v3/src/c++11/codecvt.cc:312:24: warning: left shift count >= width of type Date: Fri, 11 Mar 2022 00:22:05 +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: 12.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: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cf_reconfirmed_on bug_status 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, 11 Mar 2022 00:22:06 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104875 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2022-03-11 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 --- Comment #1 from Jonathan Wakely --- (c1 << 12) is wrong too, because it loses the high bits. We should just declare all those variables as char32_t in the first place. --- a/libstdc++-v3/src/c++11/codecvt.cc +++ b/libstdc++-v3/src/c++11/codecvt.cc @@ -254,7 +254,7 @@ namespace const size_t avail =3D from.size(); if (avail =3D=3D 0) return incomplete_mb_character; - unsigned char c1 =3D from[0]; + char32_t c1 =3D (unsigned char) from[0]; // https://en.wikipedia.org/wiki/UTF-8#Sample_code if (c1 < 0x80) { @@ -267,7 +267,7 @@ namespace { if (avail < 2) return incomplete_mb_character; - unsigned char c2 =3D from[1]; + char32_t c2 =3D (unsigned char) from[1]; if ((c2 & 0xC0) !=3D 0x80) return invalid_mb_sequence; char32_t c =3D (c1 << 6) + c2 - 0x3080; @@ -279,12 +279,12 @@ namespace { if (avail < 3) return incomplete_mb_character; - unsigned char c2 =3D from[1]; + char32_t c2 =3D (unsigned char) from[1]; if ((c2 & 0xC0) !=3D 0x80) return invalid_mb_sequence; if (c1 =3D=3D 0xE0 && c2 < 0xA0) // overlong return invalid_mb_sequence; - unsigned char c3 =3D from[2]; + char32_t c3 =3D (unsigned char) from[2]; if ((c3 & 0xC0) !=3D 0x80) return invalid_mb_sequence; char32_t c =3D (c1 << 12) + (c2 << 6) + c3 - 0xE2080; @@ -296,17 +296,17 @@ namespace { if (avail < 4) return incomplete_mb_character; - unsigned char c2 =3D from[1]; + char32_t c2 =3D (unsigned char) from[1]; if ((c2 & 0xC0) !=3D 0x80) return invalid_mb_sequence; if (c1 =3D=3D 0xF0 && c2 < 0x90) // overlong return invalid_mb_sequence; if (c1 =3D=3D 0xF4 && c2 >=3D 0x90) // > U+10FFFF return invalid_mb_sequence; - unsigned char c3 =3D from[2]; + char32_t c3 =3D (unsigned char) from[2]; if ((c3 & 0xC0) !=3D 0x80) return invalid_mb_sequence; - unsigned char c4 =3D from[3]; + char32_t c4 =3D (unsigned char) from[3]; if ((c4 & 0xC0) !=3D 0x80) return invalid_mb_sequence; char32_t c =3D (c1 << 18) + (c2 << 12) + (c3 << 6) + c4 - 0x3C82080;=