148fb7bfaSmrg // Iostreams base classes -*- C++ -*- 248fb7bfaSmrg 3*b1e83836Smrg // Copyright (C) 1997-2022 Free Software Foundation, Inc. 448fb7bfaSmrg // 548fb7bfaSmrg // This file is part of the GNU ISO C++ Library. This library is free 648fb7bfaSmrg // software; you can redistribute it and/or modify it under the 748fb7bfaSmrg // terms of the GNU General Public License as published by the 848fb7bfaSmrg // Free Software Foundation; either version 3, or (at your option) 948fb7bfaSmrg // any later version. 1048fb7bfaSmrg 1148fb7bfaSmrg // This library is distributed in the hope that it will be useful, 1248fb7bfaSmrg // but WITHOUT ANY WARRANTY; without even the implied warranty of 1348fb7bfaSmrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1448fb7bfaSmrg // GNU General Public License for more details. 1548fb7bfaSmrg 1648fb7bfaSmrg // Under Section 7 of GPL version 3, you are granted additional 1748fb7bfaSmrg // permissions described in the GCC Runtime Library Exception, version 1848fb7bfaSmrg // 3.1, as published by the Free Software Foundation. 1948fb7bfaSmrg 2048fb7bfaSmrg // You should have received a copy of the GNU General Public License and 2148fb7bfaSmrg // a copy of the GCC Runtime Library Exception along with this program; 2248fb7bfaSmrg // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 2348fb7bfaSmrg // <http://www.gnu.org/licenses/>. 2448fb7bfaSmrg 2548fb7bfaSmrg // 264d5abbe8Smrg // ISO C++ 14882:1998: 27.4.2.1.1 Class ios_base::failure 2748fb7bfaSmrg // 2848fb7bfaSmrg 294d5abbe8Smrg #define _GLIBCXX_USE_CXX11_ABI 0 3048fb7bfaSmrg #include <ios> 3148fb7bfaSmrg 32d79abf08Smrg #if _GLIBCXX_USE_DUAL_ABI && __cpp_rtti 33d79abf08Smrg #include <cxxabi.h> 34d79abf08Smrg #include <typeinfo> 35d79abf08Smrg #endif 36d79abf08Smrg 37d79abf08Smrg #ifdef _GLIBCXX_USE_NLS 38d79abf08Smrg # include <libintl.h> 39d79abf08Smrg # define _(msgid) gettext (msgid) 40d79abf08Smrg #else 41d79abf08Smrg # define _(msgid) (msgid) 42d79abf08Smrg #endif 43d79abf08Smrg 4448fb7bfaSmrg namespace std _GLIBCXX_VISIBILITY(default) 4548fb7bfaSmrg { 4648fb7bfaSmrg _GLIBCXX_BEGIN_NAMESPACE_VERSION 4748fb7bfaSmrg failure(const string & __str)4848fb7bfaSmrg ios_base::failure::failure(const string& __str) throw() 4948fb7bfaSmrg : _M_msg(__str) { } 5048fb7bfaSmrg ~failure()5148fb7bfaSmrg ios_base::failure::~failure() throw() 5248fb7bfaSmrg { } 5348fb7bfaSmrg 5448fb7bfaSmrg const char* what() const5548fb7bfaSmrg ios_base::failure::what() const throw() 5648fb7bfaSmrg { return _M_msg.c_str(); } 5748fb7bfaSmrg 58b17d1066Smrg #if _GLIBCXX_USE_DUAL_ABI 59b17d1066Smrg // When the dual ABI is enabled __throw_ios_failure() is defined in 60b17d1066Smrg // src/c++11/cxx11-ios_failure.cc 61b17d1066Smrg #if __cpp_rtti 62b17d1066Smrg // If RTTI is enabled the exception type thrown will use these functions to 63b17d1066Smrg // construct/destroy a gcc4-compatible ios::failure object in a buffer, 64b17d1066Smrg // and to catch that object via a handler of the gcc4-compatible type. 65b17d1066Smrg void __construct_ios_failure(void * buf,const char * msg)66b17d1066Smrg __construct_ios_failure(void* buf, const char* msg) 67b17d1066Smrg { ::new(buf) ios_base::failure(msg); } 68d79abf08Smrg 69b17d1066Smrg void __destroy_ios_failure(void * buf)70b17d1066Smrg __destroy_ios_failure(void* buf) 71b17d1066Smrg { static_cast<ios_base::failure*>(buf)->~failure(); } 72d79abf08Smrg 73d79abf08Smrg bool __is_ios_failure_handler(const __cxxabiv1::__class_type_info * type)74b17d1066Smrg __is_ios_failure_handler(const __cxxabiv1::__class_type_info* type) 75b17d1066Smrg { return *type == typeid(ios::failure); } 76d79abf08Smrg 77b17d1066Smrg namespace { 78b17d1066Smrg // C++98-style static assertions to ensure ios::failure fits in a buffer 79b17d1066Smrg // with the same size and alignment as runtime_error: 80b17d1066Smrg typedef char S[1 / (sizeof(ios::failure) <= sizeof(runtime_error))]; 81b17d1066Smrg typedef char A[1 / (__alignof(ios::failure) <= __alignof(runtime_error))]; 82b17d1066Smrg } 83b17d1066Smrg #endif // __cpp_rtti 84d79abf08Smrg 85b17d1066Smrg #else // ! _GLIBCXX_USE_DUAL_ABI 86d79abf08Smrg 87d79abf08Smrg void __throw_ios_failure(const char * __s)88d79abf08Smrg __throw_ios_failure(const char* __s __attribute__((unused))) 89b17d1066Smrg { _GLIBCXX_THROW_OR_ABORT(ios::failure(_(__s))); } 90b17d1066Smrg 91181254a7Smrg void __throw_ios_failure(const char * str,int)92181254a7Smrg __throw_ios_failure(const char* str, int) 93181254a7Smrg { __throw_ios_failure(str); } 94181254a7Smrg 95181254a7Smrg #endif // _GLIBCXX_USE_DUAL_ABI 96d79abf08Smrg 9748fb7bfaSmrg _GLIBCXX_END_NAMESPACE_VERSION 9848fb7bfaSmrg } // namespace 99