From patchwork Mon Nov 28 13:25:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 127983 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 7B641B6F89 for ; Tue, 29 Nov 2011 00:26:54 +1100 (EST) Received: (qmail 22197 invoked by alias); 28 Nov 2011 13:26:52 -0000 Received: (qmail 22177 invoked by uid 22791); 28 Nov 2011 13:26:49 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from acsinet15.oracle.com (HELO acsinet15.oracle.com) (141.146.126.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 Nov 2011 13:26:31 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by acsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id pASDQTkU029162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 28 Nov 2011 13:26:30 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id pASDQSUx009040 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 28 Nov 2011 13:26:29 GMT Received: from abhmt106.oracle.com (abhmt106.oracle.com [141.146.116.58]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id pASDQNO2028084; Mon, 28 Nov 2011 07:26:23 -0600 Received: from [192.168.1.4] (/79.56.212.117) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 28 Nov 2011 05:26:23 -0800 Message-ID: <4ED38BCB.40104@oracle.com> Date: Mon, 28 Nov 2011 14:25:31 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] libstdc++/51288 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, when I implemented get/put_money I gorgot about the sentry, oops. Tested x86_64-linux, committed to mainline. Paolo. ///////////////////// 2011-11-28 Paolo Carlini 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. Index: include/std/iomanip =================================================================== --- include/std/iomanip (revision 181773) +++ include/std/iomanip (working copy) @@ -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 @@ 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()); + 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; - __mg.get(_Iter(__is.rdbuf()), _Iter(), __f._M_intl, - __is, __err, __f._M_mon); - - if (ios_base::goodbit != __err) - __is.setstate(__err); - + 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 @@ 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; } Index: testsuite/27_io/manipulators/extended/put_money/wchar_t/51288.cc =================================================================== --- testsuite/27_io/manipulators/extended/put_money/wchar_t/51288.cc (revision 0) +++ testsuite/27_io/manipulators/extended/put_money/wchar_t/51288.cc (revision 0) @@ -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 +// . + +#include +#include +#include + +// 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; +} Index: testsuite/27_io/manipulators/extended/put_money/char/51288.cc =================================================================== --- testsuite/27_io/manipulators/extended/put_money/char/51288.cc (revision 0) +++ testsuite/27_io/manipulators/extended/put_money/char/51288.cc (revision 0) @@ -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 +// . + +#include +#include +#include + +// 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; +} Index: testsuite/27_io/manipulators/extended/get_money/wchar_t/51288.cc =================================================================== --- testsuite/27_io/manipulators/extended/get_money/wchar_t/51288.cc (revision 0) +++ testsuite/27_io/manipulators/extended/get_money/wchar_t/51288.cc (revision 0) @@ -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 +// . + +#include +#include +#include + +// 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; +} Index: testsuite/27_io/manipulators/extended/get_money/char/51288.cc =================================================================== --- testsuite/27_io/manipulators/extended/get_money/char/51288.cc (revision 0) +++ testsuite/27_io/manipulators/extended/get_money/char/51288.cc (revision 0) @@ -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 +// . + +#include +#include +#include + +// 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; +}