diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2018-04-10 15:36:09 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2018-04-10 15:36:09 +0100 |
commit | 5f302518627efd04b04a0da3269541fdfa2d7388 (patch) | |
tree | 61827d3ab46d9b1ce75aff26b727ee20233f7475 /libstdc++-v3/testsuite | |
parent | 7e6b73b1c00c7025b344af2796539aef61ef5474 (diff) | |
download | gcc-5f302518627efd04b04a0da3269541fdfa2d7388.zip gcc-5f302518627efd04b04a0da3269541fdfa2d7388.tar.gz gcc-5f302518627efd04b04a0da3269541fdfa2d7388.tar.bz2 |
PR libstdc++/85222 allow catching iostream errors as gcc4-compatible ios::failure
Define a new exception type derived from std::ios::failure[abi:cxx11]
which also aggregates an object of the gcc4-compatible ios::failure
type. Make __throw_ios_failure throw this new type for iostream errors
that raise exceptions. Provide custom type info for the new type so that
it can be caught by handlers for the gcc4-compatible ios::failure type
as well as handlers for ios::failure[abi:cxx11] and its bases.
PR libstdc++/85222
* src/c++11/Makefile.am [ENABLE_DUAL_ABI]: Add special rules for
cxx11-ios_failure.cc to rewrite type info for __ios_failure.
* src/c++11/Makefile.in: Regenerate.
* src/c++11/cxx11-ios_failure.cc (__ios_failure, __iosfail_type_info):
New types.
[_GLIBCXX_USE_DUAL_ABI] (__throw_ios_failure): Define here.
* src/c++11/ios.cc (__throw_ios_failure): Remove definition.
* src/c++98/ios_failure.cc (__construct_ios_failure)
(__destroy_ios_failure, is_ios_failure_handler): New functions.
[!_GLIBCXX_USE_DUAL_ABI] (__throw_ios_failure): Define here.
* testsuite/27_io/ios_base/failure/dual_abi.cc: New.
* testsuite/27_io/basic_ios/copyfmt/char/1.cc: Revert changes to
handler types, to always catch std::ios_base::failure.
* testsuite/27_io/basic_ios/exceptions/char/1.cc: Likewise.
* testsuite/27_io/basic_istream/extractors_arithmetic/char/
exceptions_failbit.cc: Likewise.
* testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/
exceptions_failbit.cc: Likewise.
* testsuite/27_io/basic_istream/extractors_other/char/
exceptions_null.cc: Likewise.
* testsuite/27_io/basic_istream/extractors_other/wchar_t/
exceptions_null.cc: Likewise.
* testsuite/27_io/basic_istream/sentry/char/12297.cc: Likewise.
* testsuite/27_io/basic_istream/sentry/wchar_t/12297.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_other/char/
exceptions_null.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_other/wchar_t/
exceptions_null.cc: Likewise.
* testsuite/27_io/ios_base/storage/2.cc: Likewise.
From-SVN: r259281
Diffstat (limited to 'libstdc++-v3/testsuite')
12 files changed, 113 insertions, 91 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/copyfmt/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ios/copyfmt/char/1.cc index ee28afa..8bcd875 100644 --- a/libstdc++-v3/testsuite/27_io/basic_ios/copyfmt/char/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_ios/copyfmt/char/1.cc @@ -46,13 +46,6 @@ void test02() } { - // The library throws the new definition of std::ios::failure -#if _GLIBCXX_USE_CXX11_ABI - typedef std::ios_base::failure exception_type; -#else - typedef std::exception exception_type; -#endif - std::ios ios_01(0); std::ios ios_02(0); ios_01.clear(std::ios_base::eofbit); @@ -62,7 +55,7 @@ void test02() ios_01.copyfmt(ios_02); VERIFY( false ); } - catch(exception_type&) { + catch(std::ios_base::failure&) { VERIFY( true ); } catch(...) { diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/1.cc index bbe4bf9..960ae27 100644 --- a/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/1.cc @@ -50,20 +50,13 @@ void test01() } { - // The library throws the new definition of std::ios::failure -#if _GLIBCXX_USE_CXX11_ABI - typedef std::ios_base::failure exception_type; -#else - typedef std::exception exception_type; -#endif - std::ios ios_01(0); ios_01.clear(std::ios_base::eofbit); try { ios_01.exceptions(std::ios_base::eofbit); VERIFY( false ); } - catch(exception_type&) { + catch(std::ios_base::failure&) { iostate02 = ios_01.exceptions(); VERIFY( static_cast<bool>(iostate02 & std::ios_base::eofbit) ); } diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc index bf96bba..584c278 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc @@ -27,20 +27,13 @@ void test_failbit() istringstream stream("jaylib - champion sound"); stream.exceptions(ios_base::failbit); - // The library throws the new definition of std::ios::failure -#if _GLIBCXX_USE_CXX11_ABI - typedef std::ios_base::failure exception_type; -#else - typedef std::exception exception_type; -#endif - try { T i; stream >> i; VERIFY( false ); } - catch (const exception_type&) + catch (const std::ios_base::failure&) { // stream should set failbit and throw ios_base::failure. VERIFY( stream.fail() ); diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit.cc index 4883d63..ca0e8b1 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit.cc @@ -27,20 +27,13 @@ void test_failbit() wistringstream stream(L"jaylib - champion sound"); stream.exceptions(ios_base::failbit); - // The library throws the new definition of std::ios::failure -#if _GLIBCXX_USE_CXX11_ABI - typedef std::ios_base::failure exception_type; -#else - typedef std::exception exception_type; -#endif - try { T i; stream >> i; VERIFY( false ); } - catch (const exception_type&) + catch (const std::ios_base::failure&) { // stream should set failbit and throw ios_base::failure. VERIFY( stream.fail() ); diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc index 5133b40..498ab21 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc @@ -35,19 +35,12 @@ void test4() istringstream stream; stream.exceptions(ios_base::failbit); - // The library throws the new definition of std::ios::failure -#if _GLIBCXX_USE_CXX11_ABI - typedef std::ios_base::failure exception_type; -#else - typedef std::exception exception_type; -#endif - try { stream >> static_cast<streambuf*>(0); VERIFY(false); } - catch (exception_type&) + catch (std::ios_base::failure&) { } diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_null.cc index 05fedd0..0c10ec6 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_null.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_null.cc @@ -35,19 +35,12 @@ void test4() wistringstream stream; stream.exceptions(ios_base::failbit); - // The library throws the new definition of std::ios::failure -#if _GLIBCXX_USE_CXX11_ABI - typedef std::ios_base::failure exception_type; -#else - typedef std::exception exception_type; -#endif - try { stream >> static_cast<wstreambuf*>(0); VERIFY( false ); } - catch (exception_type&) + catch (std::ios_base::failure&) { } diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc index a5a2dfb..c808cb7 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc @@ -26,19 +26,12 @@ int main() istringstream stream; stream.exceptions(ios_base::eofbit); - // The library throws the new definition of std::ios::failure -#if _GLIBCXX_USE_CXX11_ABI - typedef std::ios_base::failure exception_type; -#else - typedef std::exception exception_type; -#endif - try { istream::sentry sentry(stream, false); VERIFY( false ); } - catch (exception_type&) + catch (std::ios_base::failure&) { VERIFY( stream.rdstate() == (ios_base::eofbit | ios_base::failbit) ); } diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/12297.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/12297.cc index ec7ed9a..a5e03ae 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/12297.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/12297.cc @@ -26,19 +26,12 @@ int main() wistringstream stream; stream.exceptions(ios_base::eofbit); - // The library throws the new definition of std::ios::failure -#if _GLIBCXX_USE_CXX11_ABI - typedef std::ios_base::failure exception_type; -#else - typedef std::exception exception_type; -#endif - try { wistream::sentry sentry(stream, false); VERIFY( false ); } - catch (exception_type&) + catch (std::ios_base::failure&) { VERIFY( stream.rdstate() == (ios_base::eofbit | ios_base::failbit) ); } diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc index 4fc00ed..515c6be 100644 --- a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc @@ -37,19 +37,12 @@ void test3() ostringstream stream; stream.exceptions(ios_base::badbit); - // The library throws the new definition of std::ios::failure -#if _GLIBCXX_USE_CXX11_ABI - typedef std::ios_base::failure exception_type; -#else - typedef std::exception exception_type; -#endif - try { stream << static_cast<streambuf*>(0); VERIFY( false ); } - catch (exception_type&) + catch (std::ios_base::failure&) { } diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc index 685e650..25dfa30 100644 --- a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc @@ -37,19 +37,12 @@ void test3() wostringstream stream; stream.exceptions(ios_base::badbit); - // The library throws the new definition of std::ios::failure -#if _GLIBCXX_USE_CXX11_ABI - typedef std::ios_base::failure exception_type; -#else - typedef std::exception exception_type; -#endif - try { stream << static_cast<wstreambuf*>(0); VERIFY( false ); } - catch (exception_type&) + catch (std::ios_base::failure&) { } diff --git a/libstdc++-v3/testsuite/27_io/ios_base/failure/dual_abi.cc b/libstdc++-v3/testsuite/27_io/ios_base/failure/dual_abi.cc new file mode 100644 index 0000000..9bd72a1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/failure/dual_abi.cc @@ -0,0 +1,99 @@ +// Copyright (C) 2018 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/>. + +// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" } +// { dg-do run { target c++11 } } + +#include <fstream> +#include <system_error> +#include <testsuite_hooks.h> + +void +test01() +{ + using std::ios; + bool caught_ios_failure = false; + bool rethrown = false; + bool caught_system_error = false; + try { + std::ifstream f; + f.exceptions(ios::failbit | ios::badbit | ios::eofbit); + try { + f.get(); + } + catch (const ios::failure&) // catch as old ABI type + { + caught_ios_failure = true; +#if _GLIBCXX_USE_DUAL_ABI || _GLIBCXX_USE_CXX11_ABI == 1 + rethrown = true; + throw; // re-throw, to catch as new ABI type +#endif + } + } + catch (const std::system_error& e) + { + caught_system_error = true; + } + + VERIFY( caught_ios_failure ); + if (rethrown) + VERIFY( caught_system_error ); +} + +void +test02() +{ + using std::ios; + const std::exception* p = nullptr; + bool caught_ios_failure = false; + bool caught_exception = false; + try { + std::ifstream f; + f.exceptions(ios::failbit | ios::badbit | ios::eofbit); + try { + f.get(); + } + catch (const std::exception& e1) + { + caught_exception = true; + p = &e1; + throw; + } + } + catch (const ios::failure& e2) + { + caught_ios_failure = true; +#if _GLIBCXX_USE_DUAL_ABI + // If the Dual ABI is active the library throws the new type, + // so e1 was an object of that new type and so &e1 != &e2. + VERIFY( p != &e2 ); +#else + // Otherwise there's only one type of ios::failure, so &e1 == &e2. + VERIFY( p == &e2 ); +#endif + } + + VERIFY( caught_exception ); + VERIFY( caught_ios_failure ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/storage/2.cc b/libstdc++-v3/testsuite/27_io/ios_base/storage/2.cc index e0f783e..6a064e2 100644 --- a/libstdc++-v3/testsuite/27_io/ios_base/storage/2.cc +++ b/libstdc++-v3/testsuite/27_io/ios_base/storage/2.cc @@ -50,18 +50,11 @@ void test02() ios.pword(1) = v; VERIFY( ios.pword(1) == v ); - // The library throws the new definition of std::ios::failure -#if _GLIBCXX_USE_CXX11_ABI - typedef std::ios_base::failure exception_type; -#else - typedef std::exception exception_type; -#endif - try { v = ios.pword(max); } - catch(exception_type&) + catch(std::ios_base::failure&) { // Ok. VERIFY( ios.bad() ); @@ -80,7 +73,7 @@ void test02() { v = ios.pword(std::numeric_limits<int>::max()); } - catch(exception_type&) + catch(std::ios_base::failure&) { // Ok. VERIFY( ios.bad() ); @@ -99,7 +92,7 @@ void test02() { l = ios.iword(max); } - catch(exception_type&) + catch(std::ios_base::failure&) { // Ok. VERIFY( ios.bad() ); @@ -118,7 +111,7 @@ void test02() { l = ios.iword(std::numeric_limits<int>::max()); } - catch(exception_type&) + catch(std::ios_base::failure&) { // Ok. VERIFY( ios.bad() ); |