1*38fd1498Szrj // Iostreams base classes -*- C++ -*- 2*38fd1498Szrj 3*38fd1498Szrj // Copyright (C) 1997-2018 Free Software Foundation, Inc. 4*38fd1498Szrj // 5*38fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free 6*38fd1498Szrj // software; you can redistribute it and/or modify it under the 7*38fd1498Szrj // terms of the GNU General Public License as published by the 8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option) 9*38fd1498Szrj // any later version. 10*38fd1498Szrj 11*38fd1498Szrj // This library is distributed in the hope that it will be useful, 12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of 13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*38fd1498Szrj // GNU General Public License for more details. 15*38fd1498Szrj 16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional 17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version 18*38fd1498Szrj // 3.1, as published by the Free Software Foundation. 19*38fd1498Szrj 20*38fd1498Szrj // You should have received a copy of the GNU General Public License and 21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program; 22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23*38fd1498Szrj // <http://www.gnu.org/licenses/>. 24*38fd1498Szrj 25*38fd1498Szrj // 26*38fd1498Szrj // ISO C++ 14882:1998: 27.4.2.1.1 Class ios_base::failure 27*38fd1498Szrj // 28*38fd1498Szrj 29*38fd1498Szrj #define _GLIBCXX_USE_CXX11_ABI 0 30*38fd1498Szrj #include <ios> 31*38fd1498Szrj 32*38fd1498Szrj #if _GLIBCXX_USE_DUAL_ABI && __cpp_rtti 33*38fd1498Szrj #include <cxxabi.h> 34*38fd1498Szrj #include <typeinfo> 35*38fd1498Szrj #endif 36*38fd1498Szrj 37*38fd1498Szrj #ifdef _GLIBCXX_USE_NLS 38*38fd1498Szrj # include <libintl.h> 39*38fd1498Szrj # define _(msgid) gettext (msgid) 40*38fd1498Szrj #else 41*38fd1498Szrj # define _(msgid) (msgid) 42*38fd1498Szrj #endif 43*38fd1498Szrj 44*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default) 45*38fd1498Szrj { 46*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION 47*38fd1498Szrj failure(const string & __str)48*38fd1498Szrj ios_base::failure::failure(const string& __str) throw() 49*38fd1498Szrj : _M_msg(__str) { } 50*38fd1498Szrj ~failure()51*38fd1498Szrj ios_base::failure::~failure() throw() 52*38fd1498Szrj { } 53*38fd1498Szrj 54*38fd1498Szrj const char* what() const55*38fd1498Szrj ios_base::failure::what() const throw() 56*38fd1498Szrj { return _M_msg.c_str(); } 57*38fd1498Szrj 58*38fd1498Szrj #if _GLIBCXX_USE_DUAL_ABI 59*38fd1498Szrj // When the dual ABI is enabled __throw_ios_failure() is defined in 60*38fd1498Szrj // src/c++11/cxx11-ios_failure.cc 61*38fd1498Szrj #if __cpp_rtti 62*38fd1498Szrj // If RTTI is enabled the exception type thrown will use these functions to 63*38fd1498Szrj // construct/destroy a gcc4-compatible ios::failure object in a buffer, 64*38fd1498Szrj // and to catch that object via a handler of the gcc4-compatible type. 65*38fd1498Szrj void __construct_ios_failure(void * buf,const char * msg)66*38fd1498Szrj __construct_ios_failure(void* buf, const char* msg) 67*38fd1498Szrj { ::new(buf) ios_base::failure(msg); } 68*38fd1498Szrj 69*38fd1498Szrj void __destroy_ios_failure(void * buf)70*38fd1498Szrj __destroy_ios_failure(void* buf) 71*38fd1498Szrj { static_cast<ios_base::failure*>(buf)->~failure(); } 72*38fd1498Szrj 73*38fd1498Szrj bool __is_ios_failure_handler(const __cxxabiv1::__class_type_info * type)74*38fd1498Szrj __is_ios_failure_handler(const __cxxabiv1::__class_type_info* type) 75*38fd1498Szrj { return *type == typeid(ios::failure); } 76*38fd1498Szrj 77*38fd1498Szrj namespace { 78*38fd1498Szrj // C++98-style static assertions to ensure ios::failure fits in a buffer 79*38fd1498Szrj // with the same size and alignment as runtime_error: 80*38fd1498Szrj typedef char S[1 / (sizeof(ios::failure) <= sizeof(runtime_error))]; 81*38fd1498Szrj typedef char A[1 / (__alignof(ios::failure) <= __alignof(runtime_error))]; 82*38fd1498Szrj } 83*38fd1498Szrj #endif // __cpp_rtti 84*38fd1498Szrj 85*38fd1498Szrj #else // ! _GLIBCXX_USE_DUAL_ABI 86*38fd1498Szrj 87*38fd1498Szrj void __throw_ios_failure(const char * __s)88*38fd1498Szrj __throw_ios_failure(const char* __s __attribute__((unused))) 89*38fd1498Szrj { _GLIBCXX_THROW_OR_ABORT(ios::failure(_(__s))); } 90*38fd1498Szrj 91*38fd1498Szrj #endif 92*38fd1498Szrj 93*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION 94*38fd1498Szrj } // namespace 95