+2018-08-08 Jonathan Wakely <jwakely@redhat.com>
+
+ PR libstdc++/66145
+ Backport from mainline
+ 2018-04-10 Jonathan Wakely <jwakely@redhat.com>
+
+ PR libstdc++/85222
+ * src/c++11/cxx11-ios_failure.cc (__construct_ios_failure)
+ (__destroy_ios_failure, is_ios_failure_handler): New functions.
+ * src/c++11/ios.cc (__throw_ios_failure): Remove definition.
+ (_GLIBCXX_USE_CXX11_ABI): Don't define here.
+ * src/c++98/Makefile.am [ENABLE_DUAL_ABI]: Add special rules for
+ ios_failure.cc to rewrite type info for __ios_failure.
+ * src/c++98/Makefile.in: Regenerate.
+ * src/c++98/ios_failure.cc [_GLIBCXX_USE_DUAL_ABI]
+ (__iosfailure, __iosfailure_type_info): New types.
+ (__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
+ add -D_GLIBCXX_USE_CXX11_ABI=0 to dg-options.
+ * 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.
+
2018-07-05 François Dumont <fdumont@gcc.gnu.org>
Backport from mainline
#define _GLIBCXX_USE_CXX11_ABI 1
#include <ios>
+#include <typeinfo>
+#include <cxxabi.h>
#if ! _GLIBCXX_USE_DUAL_ABI
# error This file should not be compiled for this configuration.
ios_base::failure::what() const throw()
{ return runtime_error::what(); }
+ // __throw_ios_failure() is defined in src/c++98/ios_failure.cc
+
+#if __cpp_rtti
+ // If RTTI is enabled the exception type thrown will use these functions to
+ // construct/destroy a ios::failure[abi:cxx11] object in a buffer,
+ // and to catch that object via a handler of the [abi:cxx11] type.
+ void
+ __construct_ios_failure(void* buf, const char* msg)
+ { ::new(buf) ios_base::failure(msg); }
+
+ void
+ __destroy_ios_failure(void* buf)
+ { static_cast<ios_base::failure*>(buf)->~failure(); }
+
+ bool
+ __is_ios_failure_handler(const __cxxabiv1::__class_type_info* type)
+ { return *type == typeid(ios::failure); }
+
+ // static assertions to ensure ios::failure fits in a buffer
+ // with the same size and alignment as system_error:
+ static_assert(sizeof(ios::failure) <= sizeof(system_error), "");
+ static_assert(__alignof(ios::failure) <= __alignof(system_error), "");
+#endif // __cpp_rtti
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
// ISO C++ 14882: 27.4 Iostreams base classes
//
-// Determines the version of ios_base::failure thrown by __throw_ios_failure.
-// If !_GLIBCXX_USE_DUAL_ABI this will get undefined automatically.
-#define _GLIBCXX_USE_CXX11_ABI 0
-
#include <ios>
#include <limits>
-#include <bits/functexcept.h>
-
-#ifdef _GLIBCXX_USE_NLS
-# include <libintl.h>
-# define _(msgid) gettext (msgid)
-#else
-# define _(msgid) (msgid)
-#endif
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
- void
- __throw_ios_failure(const char* __s __attribute__((unused)))
- { _GLIBCXX_THROW_OR_ABORT(ios_base::failure(_(__s))); }
-
// Definitions for static const members of ios_base.
const ios_base::fmtflags ios_base::boolalpha;
const ios_base::fmtflags ios_base::dec;
parallel_settings.o: parallel_settings.cc
$(CXXCOMPILE) $(PARALLEL_FLAGS) -c $<
+if ENABLE_DUAL_ABI
+# Rewrite the type info for __iosfailure.
+rewrite_ios_failure_typeinfo = sed -e '/^_*_ZTISt12__iosfailure:/,/_ZTVN10__cxxabiv120__si_class_type_infoE/s/_ZTVN10__cxxabiv120__si_class_type_infoE/_ZTVSt22__iosfailure_type_info/'
+
+ios_failure-lt.s: ios_failure.cc
+ $(LTCXXCOMPILE) -S $< -o tmp-ios_failure-lt.s
+ -test -f tmp-ios_failure-lt.o && mv -f tmp-ios_failure-lt.o tmp-ios_failure-lt.s
+ $(rewrite_ios_failure_typeinfo) tmp-$@ > $@
+ -rm -f tmp-$@
+ios_failure.s: ios_failure.cc
+ $(CXXCOMPILE) -S $< -o tmp-$@
+ $(rewrite_ios_failure_typeinfo) tmp-$@ > $@
+ -rm -f tmp-$@
+
+ios_failure.lo: ios_failure-lt.s
+ $(LTCXXCOMPILE) -g0 -c $< -o $@
+ios_failure.o: ios_failure.s
+ $(CXXCOMPILE) -g0 -c $<
+endif
+
# AM_CXXFLAGS needs to be in each subdirectory so that it can be
# modified in a per-library or per-sub-library way. Need to manually
# set this option because CONFIG_CXXFLAGS has to be after
# Use special rules for parallel mode compilation.
PARALLEL_FLAGS = -D_GLIBCXX_PARALLEL
+# Rewrite the type info for __iosfailure.
+@ENABLE_DUAL_ABI_TRUE@rewrite_ios_failure_typeinfo = sed -e '/^_*_ZTISt12__iosfailure:/,/_ZTVN10__cxxabiv120__si_class_type_infoE/s/_ZTVN10__cxxabiv120__si_class_type_infoE/_ZTVSt22__iosfailure_type_info/'
+
# AM_CXXFLAGS needs to be in each subdirectory so that it can be
# modified in a per-library or per-sub-library way. Need to manually
# set this option because CONFIG_CXXFLAGS has to be after
parallel_settings.o: parallel_settings.cc
$(CXXCOMPILE) $(PARALLEL_FLAGS) -c $<
+@ENABLE_DUAL_ABI_TRUE@ios_failure-lt.s: ios_failure.cc
+@ENABLE_DUAL_ABI_TRUE@ $(LTCXXCOMPILE) -S $< -o tmp-ios_failure-lt.s
+@ENABLE_DUAL_ABI_TRUE@ -test -f tmp-ios_failure-lt.o && mv -f tmp-ios_failure-lt.o tmp-ios_failure-lt.s
+@ENABLE_DUAL_ABI_TRUE@ $(rewrite_ios_failure_typeinfo) tmp-$@ > $@
+@ENABLE_DUAL_ABI_TRUE@ -rm -f tmp-$@
+@ENABLE_DUAL_ABI_TRUE@ios_failure.s: ios_failure.cc
+@ENABLE_DUAL_ABI_TRUE@ $(CXXCOMPILE) -S $< -o tmp-$@
+@ENABLE_DUAL_ABI_TRUE@ $(rewrite_ios_failure_typeinfo) tmp-$@ > $@
+@ENABLE_DUAL_ABI_TRUE@ -rm -f tmp-$@
+
+@ENABLE_DUAL_ABI_TRUE@ios_failure.lo: ios_failure-lt.s
+@ENABLE_DUAL_ABI_TRUE@ $(LTCXXCOMPILE) -c $< -o $@
+@ENABLE_DUAL_ABI_TRUE@ios_failure.o: ios_failure.s
+@ENABLE_DUAL_ABI_TRUE@ $(CXXCOMPILE) -c $<
+
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
#define _GLIBCXX_USE_CXX11_ABI 0
#include <ios>
+#if _GLIBCXX_USE_DUAL_ABI && __cpp_rtti
+#include <cxxabi.h>
+#include <typeinfo>
+#endif
+
+#ifdef _GLIBCXX_USE_NLS
+# include <libintl.h>
+# define _(msgid) gettext (msgid)
+#else
+# define _(msgid) (msgid)
+#endif
+
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
ios_base::failure::what() const throw()
{ return _M_msg.c_str(); }
+#if _GLIBCXX_USE_DUAL_ABI && __cpp_rtti
+ // These functions are defined in src/c++11/cxx11-ios_failure.cc
+ extern void __construct_ios_failure(void*, const char*);
+ extern void __destroy_ios_failure(void*);
+ extern bool __is_ios_failure_handler(const __cxxabiv1::__class_type_info*);
+
+ // The type thrown to report errors during stream buffer operations.
+ // In addition to the gcc4-compatible ios::failure base class it also has a
+ // member of the ios::failure[abi:cxx11] type (in an opaque buffer).
+ struct __iosfailure : std::ios::failure
+ {
+ __iosfailure(const char* s) : failure(s)
+ { __construct_ios_failure(buf, failure::what()); }
+
+ ~__iosfailure() throw()
+ { __destroy_ios_failure(buf); }
+
+ // Type that is layout-compatible with std::system_error
+ struct __system_error : std::runtime_error
+ {
+ // Type that is layout-compatible with std::error_code
+ struct error_code
+ {
+ error_code() { }
+ private:
+ int _M_value;
+ const void* _M_cat;
+ } _M_code;
+ };
+
+ // Use __system_error as a proxy for the ios::failure[abi:cxx11]
+ // (which can't be declared here because _GLIBCXX_USE_CXX11_ABI == 0).
+ // There are assertions in src/c++11/cxx11-ios_failure.cc to ensure the
+ // size and alignment assumptions are valid.
+ __attribute__((aligned(__alignof(__system_error))))
+ unsigned char buf[sizeof(__system_error)];
+ };
+
+ // Custom type info for __ios_failure.
+ class __iosfailure_type_info : __cxxabiv1::__si_class_type_info
+ {
+ ~__iosfailure_type_info();
+
+ bool
+ __do_upcast (const __class_type_info *dst_type,
+ void **obj_ptr) const;
+ };
+
+ __iosfailure_type_info::~__iosfailure_type_info() { }
+
+ // This function gets called to see if an exception of type
+ // __ios_failure can be upcast to the type in a catch handler.
+ bool
+ __iosfailure_type_info::__do_upcast(const __class_type_info *dst_type,
+ void **obj_ptr) const
+ {
+ // If the handler is for the ios::failure[abi:cxx11] type then
+ // catch the object stored in __ios_failure::buf instead of
+ // the __ios_failure exception object itself.
+ if (__is_ios_failure_handler(dst_type))
+ {
+ *obj_ptr = static_cast<__iosfailure*>(*obj_ptr)->buf;
+ return true;
+ }
+ // Otherwise proceeed as normal to see if the handler matches.
+ return __class_type_info::__do_upcast(dst_type, obj_ptr);
+ }
+#else // _GLIBCXX_USE_DUAL_ABI && __cpp_rtti
+ using __iosfailure = ios::failure;
+#endif
+
+ void
+ __throw_ios_failure(const char* __s __attribute__((unused)))
+ { _GLIBCXX_THROW_OR_ABORT(__iosfailure(_(__s))); }
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// The library still throws the original definition of std::ios::failure
-// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" }
-
// 27.4.4.2 basic_ios member functions
// NB: Don't include any other headers in this file.
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// The library still throws the original definition of std::ios::failure
-// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" }
-
// 27.4.4.2 basic_ios member functions
// NB: Don't include any other headers in this file.
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// The library still throws the original definition of std::ios::failure
-// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" }
-
#include <sstream>
#include <testsuite_hooks.h>
istringstream stream("jaylib - champion sound");
stream.exceptions(ios_base::failbit);
-
+
try
{
T i;
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// The library still throws the original definition of std::ios::failure
-// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" }
-
#include <sstream>
#include <testsuite_hooks.h>
wistringstream stream(L"jaylib - champion sound");
stream.exceptions(ios_base::failbit);
-
+
try
{
T i;
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// The library still throws the original definition of std::ios::failure
-// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" }
-
#include <istream>
#include <ostream>
#include <streambuf>
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// The library still throws the original definition of std::ios::failure
-// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" }
-
#include <istream>
#include <ostream>
#include <streambuf>
// 27.6.1.1.2 class basic_istream::sentry
-// The library still throws the original definition of std::ios::failure
-// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" }
-
#include <sstream>
#include <testsuite_hooks.h>
using namespace std;
istringstream stream;
stream.exceptions(ios_base::eofbit);
-
+
try
{
istream::sentry sentry(stream, false);
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// The library still throws the original definition of std::ios::failure
-// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" }
-
// 27.6.1.1.2 class basic_istream::sentry
#include <sstream>
using namespace std;
wistringstream stream;
stream.exceptions(ios_base::eofbit);
-
+
try
{
wistream::sentry sentry(stream, false);
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// The library still throws the original definition of std::ios::failure
-// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" }
-
#include <istream>
#include <ostream>
#include <streambuf>
ostringstream stream;
stream.exceptions(ios_base::badbit);
-
+
try
{
stream << static_cast<streambuf*>(0);
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// The library still throws the original definition of std::ios::failure
-// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" }
-
#include <istream>
#include <ostream>
#include <streambuf>
wostringstream stream;
stream.exceptions(ios_base::badbit);
-
+
try
{
stream << static_cast<wstreambuf*>(0);
--- /dev/null
+// 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=1" }
+// { dg-do run }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ using std::ios;
+ bool caught_ios_failure = false;
+ bool rethrown = false;
+ bool caught_exception = false;
+ try {
+ std::ifstream f;
+ f.exceptions(ios::failbit | ios::badbit | ios::eofbit);
+ try {
+ f.get();
+ }
+ catch (const ios::failure&) // catch as new ABI type
+ {
+ caught_ios_failure = true;
+#if _GLIBCXX_USE_DUAL_ABI || _GLIBCXX_USE_CXX11_ABI == 1
+ rethrown = true;
+ throw; // re-throw, to catch as old ABI type
+#endif
+ }
+ }
+ catch (const std::exception& e)
+ {
+ caught_exception = true;
+ }
+
+ VERIFY( caught_ios_failure );
+ if (rethrown)
+ VERIFY( caught_exception );
+}
+
+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 old type,
+ // so e1 was an object of that old 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();
+}
// Radar 6467884: 10.X systems are not robust when paging space is exceeded
// { dg-skip-if "" { *-*-darwin* && lp64 } { "*" } { "" } }
-// The library still throws the original definition of std::ios::failure
-// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" }
-
#include <sstream>
#include <iostream>
#include <limits>
// pword
ios.pword(1) = v;
VERIFY( ios.pword(1) == v );
-
- try
+
+ try
{
v = ios.pword(max);
}