From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ED9C93858031; Mon, 11 Jul 2022 11:20:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED9C93858031 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/106248] [11/12/13 Regression] operator>>std::basic_istream at boundary condition behave differently in different opt levels Date: Mon, 11 Jul 2022 11:20:07 +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: 11.2.0 X-Bugzilla-Keywords: wrong-code 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 short_desc cf_known_to_fail everconfirmed cf_known_to_work 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: Mon, 11 Jul 2022 11:20:08 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106248 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2022-07-11 Status|UNCONFIRMED |NEW Summary|operator>>std::basic_istrea |[11/12/13 Regression] |m at boundary condition |operator>>std::basic_istrea |behave differently in |m at boundary condition |different opt levels |behave differently in | |different opt levels Known to fail| |11.1.0 Ever confirmed|0 |1 Known to work| |10.4.0 --- Comment #3 from Jonathan Wakely --- In C++20 mode the operator>> overload has changed to one that binds to char (&)[10] and so knows the size of the output buffer. The loop stops reading = when it has written as many chars as will fit in the buffer, and does not set eofbit: if (__extracted < __num - 1 && __traits_type::eq_int_type(__c, __eof)) __err |=3D ios_base::eofbit; In pre-C++20 modes, operator>> just binds to a const char* and will overflo= w it if the buffer is not big enough. However, libstdc++ now uses __builtin_object_size to detect the size of the buffer, and so will stop writing when the buffer is full. That detection using __builtin_object_size only works when optimization is enabled, which is why we stop before setting the eofbit when optimizing. I don't want to just remove the size detection, because it prevents undefin= ed behaviour. But we need a way to prevent overflow without altering the observable behaviour for C++17 and earlier.=