diff mbox

std::quoted is too eager to clear the string

Message ID m38ut5qqr6.fsf@black.gullik.net
State New
Headers show

Commit Message

Lars Gullik =?iso-8859-1?Q?Bj=F8nnes?= Feb. 21, 2014, midnight UTC
* include/std/iomanip (_Quoted_string operator>>): Do not clear
   string if input is not quoted.

Currently the string is cleared regardless of
how the string is handled. This patch just
moves the clearing down so that we do not clear
it if we are not going to quote the string
(i.e. let operator>> handle the clearing if needed)
and also not if we encounter any stream error.

This has been reported as (bug 60270).

I have no GCC paperwork in order, but I expect this change
to be simple enough to not require that.

---
 libstdc++-v3/include/std/iomanip | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Jonathan Wakely Feb. 21, 2014, 12:13 a.m. UTC | #1
On 21 February 2014 00:00, Lars Gullik Bjønnes wrote:
>
>  * include/std/iomanip (_Quoted_string operator>>): Do not clear
>    string if input is not quoted.
>
> Currently the string is cleared regardless of
> how the string is handled. This patch just
> moves the clearing down so that we do not clear
> it if we are not going to quote the string
> (i.e. let operator>> handle the clearing if needed)
> and also not if we encounter any stream error.
>
> This has been reported as (bug 60270).
>
> I have no GCC paperwork in order, but I expect this change
> to be simple enough to not require that.

I agree, and we already have a testcase in the PR I opened.

I'll commit this for 4.9.1, thanks for reporting and fixing it.
diff mbox

Patch

diff --git a/libstdc++-v3/include/std/iomanip b/libstdc++-v3/include/std/iomanip
index b2c7b95..73822db 100644
--- a/libstdc++-v3/include/std/iomanip
+++ b/libstdc++-v3/include/std/iomanip
@@ -415,8 +415,6 @@  _GLIBCXX_END_NAMESPACE_VERSION
 		 const _Quoted_string<basic_string<_CharT, _Traits, _Alloc>&,
 				      _CharT>& __str)
       {
-	__str._M_string.clear();
-
 	_CharT __c;
 	__is >> __c;
 	if (!__is.good())
@@ -427,6 +425,7 @@  _GLIBCXX_END_NAMESPACE_VERSION
 	    __is >> __str._M_string;
 	    return __is;
 	  }
+	__str._M_string.clear();
 	std::ios_base::fmtflags __flags
 	  = __is.flags(__is.flags() & ~std::ios_base::skipws);
 	do