aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2011-11-28 13:24:23 +0000
committerPaolo Carlini <paolo.carlini@oracle.com>2011-11-28 13:24:23 +0000
commit5c5a39b74bcdc49f7f43975d24f196d0588de6d0 (patch)
tree61eec1379f39f4ec6f58c7d4c6168d21fff6fa31
parent8d79011432d56cff434afeb4801a4424fbb2a9aa (diff)
2011-11-28 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/51288 * include/std/iomanip (get_money, put_money): Use sentry. * testsuite/27_io/manipulators/extended/get_money/char/51288.cc: New. * testsuite/27_io/manipulators/extended/get_money/wchar_t/51288.cc: Likewise. * testsuite/27_io/manipulators/extended/put_money/char/51288.cc: Likewise. * testsuite/27_io/manipulators/extended/put_money/wchar_t/51288.cc: Likewise. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@181775 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog12
-rw-r--r--libstdc++-v3/include/std/iomanip68
-rw-r--r--libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/char/51288.cc48
-rw-r--r--libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/wchar_t/51288.cc48
-rw-r--r--libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/char/51288.cc49
-rw-r--r--libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/wchar_t/51288.cc49
6 files changed, 251 insertions, 23 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 81b9e9c0230..1d4dff8747c 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,15 @@
+2011-11-28 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR libstdc++/51288
+ * include/std/iomanip (get_money, put_money): Use sentry.
+ * testsuite/27_io/manipulators/extended/get_money/char/51288.cc: New.
+ * testsuite/27_io/manipulators/extended/get_money/wchar_t/51288.cc:
+ Likewise.
+ * testsuite/27_io/manipulators/extended/put_money/char/51288.cc:
+ Likewise.
+ * testsuite/27_io/manipulators/extended/put_money/wchar_t/51288.cc:
+ Likewise.
+
2011-11-27 Gerald Pfeifer <gerald@pfeifer.com>
* doc/xml/manual/using.xml (Prerequisites): Refer to x86 instead
diff --git a/libstdc++-v3/include/std/iomanip b/libstdc++-v3/include/std/iomanip
index ea2c44acf6f..e725b2514df 100644
--- a/libstdc++-v3/include/std/iomanip
+++ b/libstdc++-v3/include/std/iomanip
@@ -1,7 +1,7 @@
// Standard stream manipulators -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
-// 2006, 2007, 2008, 2009, 2010
+// 2006, 2007, 2008, 2009, 2010, 2011
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -262,18 +262,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, _Get_money<_MoneyT> __f)
{
- typedef istreambuf_iterator<_CharT, _Traits> _Iter;
- typedef money_get<_CharT, _Iter> _MoneyGet;
-
- ios_base::iostate __err = ios_base::goodbit;
- const _MoneyGet& __mg = use_facet<_MoneyGet>(__is.getloc());
-
- __mg.get(_Iter(__is.rdbuf()), _Iter(), __f._M_intl,
- __is, __err, __f._M_mon);
-
- if (ios_base::goodbit != __err)
- __is.setstate(__err);
-
+ typename basic_istream<_CharT, _Traits>::sentry __cerb(__is, false);
+ if (__cerb)
+ {
+ ios_base::iostate __err = ios_base::goodbit;
+ __try
+ {
+ typedef istreambuf_iterator<_CharT, _Traits> _Iter;
+ typedef money_get<_CharT, _Iter> _MoneyGet;
+
+ const _MoneyGet& __mg = use_facet<_MoneyGet>(__is.getloc());
+ __mg.get(_Iter(__is.rdbuf()), _Iter(), __f._M_intl,
+ __is, __err, __f._M_mon);
+ }
+ __catch(__cxxabiv1::__forced_unwind&)
+ {
+ __is._M_setstate(ios_base::badbit);
+ __throw_exception_again;
+ }
+ __catch(...)
+ { __is._M_setstate(ios_base::badbit); }
+ if (ios_base::goodbit != __err)
+ __is.setstate(__err);
+ }
return __is;
}
@@ -298,16 +309,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, _Put_money<_MoneyT> __f)
{
- typedef ostreambuf_iterator<_CharT, _Traits> _Iter;
- typedef money_put<_CharT, _Iter> _MoneyPut;
-
- const _MoneyPut& __mp = use_facet<_MoneyPut>(__os.getloc());
- const _Iter __end = __mp.put(_Iter(__os.rdbuf()), __f._M_intl,
- __os, __os.fill(), __f._M_mon);
-
- if (__end.failed())
- __os.setstate(ios_base::badbit);
-
+ typename basic_ostream<_CharT, _Traits>::sentry __cerb(__os);
+ if (__cerb)
+ {
+ __try
+ {
+ typedef ostreambuf_iterator<_CharT, _Traits> _Iter;
+ typedef money_put<_CharT, _Iter> _MoneyPut;
+ const _MoneyPut& __mp = use_facet<_MoneyPut>(__os.getloc());
+ const _Iter __end = __mp.put(_Iter(__os.rdbuf()), __f._M_intl,
+ __os, __os.fill(), __f._M_mon);
+ if (__end.failed())
+ __os.setstate(ios_base::badbit);
+ }
+ __catch(__cxxabiv1::__forced_unwind&)
+ {
+ __os._M_setstate(ios_base::badbit);
+ __throw_exception_again;
+ }
+ __catch(...)
+ { __os._M_setstate(ios_base::badbit); }
+ }
return __os;
}
diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/char/51288.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/char/51288.cc
new file mode 100644
index 00000000000..281a2e2d39c
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/char/51288.cc
@@ -0,0 +1,48 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-namedlocale "en_US.UTF-8" }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <sstream>
+#include <iomanip>
+#include <testsuite_hooks.h>
+
+// libstdc++/51288
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::locale loc_us = std::locale("en_US.UTF-8");
+
+ std::istringstream iss;
+ iss.imbue(loc_us);
+
+ iss.str(" $1.23");
+
+ std::string str;
+ iss >> std::get_money(str);
+
+ VERIFY( str == "123" );
+ VERIFY( iss.eof() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/wchar_t/51288.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/wchar_t/51288.cc
new file mode 100644
index 00000000000..2ec02302c31
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/wchar_t/51288.cc
@@ -0,0 +1,48 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-namedlocale "en_US.UTF-8" }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <sstream>
+#include <iomanip>
+#include <testsuite_hooks.h>
+
+// libstdc++/51288
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::locale loc_us = std::locale("en_US.UTF-8");
+
+ std::wistringstream iss;
+ iss.imbue(loc_us);
+
+ iss.str(L" $1.23");
+
+ std::wstring str;
+ iss >> std::get_money(str);
+
+ VERIFY( str == L"123" );
+ VERIFY( iss.eof() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/char/51288.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/char/51288.cc
new file mode 100644
index 00000000000..d2cc9cb7012
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/char/51288.cc
@@ -0,0 +1,49 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-namedlocale "en_US.UTF-8" }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <sstream>
+#include <iomanip>
+#include <testsuite_hooks.h>
+
+// libstdc++/51288
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::locale loc_us = std::locale("en_US.UTF-8");
+
+ std::ostringstream oss;
+ oss.imbue(loc_us);
+
+ const std::string str("123");
+
+ oss.setstate(std::ios_base::failbit);
+
+ oss << std::put_money(str);
+
+ VERIFY( oss.str().empty() );
+ VERIFY( oss.fail() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/wchar_t/51288.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/wchar_t/51288.cc
new file mode 100644
index 00000000000..548c0a7c2b4
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/wchar_t/51288.cc
@@ -0,0 +1,49 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-namedlocale "en_US.UTF-8" }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <sstream>
+#include <iomanip>
+#include <testsuite_hooks.h>
+
+// libstdc++/51288
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::locale loc_us = std::locale("en_US.UTF-8");
+
+ std::wostringstream oss;
+ oss.imbue(loc_us);
+
+ const std::wstring str(L"123");
+
+ oss.setstate(std::ios_base::failbit);
+
+ oss << std::put_money(str);
+
+ VERIFY( oss.str().empty() );
+ VERIFY( oss.fail() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}