From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6FA273854146; Mon, 11 Jul 2022 11:46:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FA273854146 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:46:50 +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: 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:46:50 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106248 --- Comment #6 from Jonathan Wakely --- I think this would restore the previous behaviour without losing the overfl= ow prevention: --- a/libstdc++-v3/include/std/istream +++ b/libstdc++-v3/include/std/istream @@ -813,8 +813,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION else { if (__n =3D=3D (size_t)-1) - __n =3D __gnu_cxx::__numeric_traits::__max; - std::__istream_extract(__in, __s, __n / sizeof(_CharT)); + { + __n =3D __gnu_cxx::__numeric_traits::__max; + std::__istream_extract(__in, __s, __n / sizeof(_CharT)); + } + else + { + std::__istream_extract(__in, __s, __n / sizeof(_CharT)); + if (__in.good() && _Traits::eq_int_type(__in.rdbuf()->snextc(= ), + _Traits::eof())) + __in.setstate(ios_base::eofbit); + } } return __in; }=