xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/src/c++98/ios_failure.cc (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
136ac495dSmrg // Iostreams base classes -*- C++ -*-
236ac495dSmrg 
3*8feb0f0bSmrg // Copyright (C) 1997-2020 Free Software Foundation, Inc.
436ac495dSmrg //
536ac495dSmrg // This file is part of the GNU ISO C++ Library.  This library is free
636ac495dSmrg // software; you can redistribute it and/or modify it under the
736ac495dSmrg // terms of the GNU General Public License as published by the
836ac495dSmrg // Free Software Foundation; either version 3, or (at your option)
936ac495dSmrg // any later version.
1036ac495dSmrg 
1136ac495dSmrg // This library is distributed in the hope that it will be useful,
1236ac495dSmrg // but WITHOUT ANY WARRANTY; without even the implied warranty of
1336ac495dSmrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1436ac495dSmrg // GNU General Public License for more details.
1536ac495dSmrg 
1636ac495dSmrg // Under Section 7 of GPL version 3, you are granted additional
1736ac495dSmrg // permissions described in the GCC Runtime Library Exception, version
1836ac495dSmrg // 3.1, as published by the Free Software Foundation.
1936ac495dSmrg 
2036ac495dSmrg // You should have received a copy of the GNU General Public License and
2136ac495dSmrg // a copy of the GCC Runtime Library Exception along with this program;
2236ac495dSmrg // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
2336ac495dSmrg // <http://www.gnu.org/licenses/>.
2436ac495dSmrg 
2536ac495dSmrg //
2636ac495dSmrg // ISO C++ 14882:1998: 27.4.2.1.1  Class ios_base::failure
2736ac495dSmrg //
2836ac495dSmrg 
2936ac495dSmrg #define _GLIBCXX_USE_CXX11_ABI 0
3036ac495dSmrg #include <ios>
3136ac495dSmrg 
3236ac495dSmrg #if _GLIBCXX_USE_DUAL_ABI && __cpp_rtti
3336ac495dSmrg #include <cxxabi.h>
3436ac495dSmrg #include <typeinfo>
3536ac495dSmrg #endif
3636ac495dSmrg 
3736ac495dSmrg #ifdef _GLIBCXX_USE_NLS
3836ac495dSmrg # include <libintl.h>
3936ac495dSmrg # define _(msgid)   gettext (msgid)
4036ac495dSmrg #else
4136ac495dSmrg # define _(msgid)   (msgid)
4236ac495dSmrg #endif
4336ac495dSmrg 
4436ac495dSmrg namespace std _GLIBCXX_VISIBILITY(default)
4536ac495dSmrg {
4636ac495dSmrg _GLIBCXX_BEGIN_NAMESPACE_VERSION
4736ac495dSmrg 
failure(const string & __str)4836ac495dSmrg   ios_base::failure::failure(const string& __str) throw()
4936ac495dSmrg   : _M_msg(__str) { }
5036ac495dSmrg 
~failure()5136ac495dSmrg   ios_base::failure::~failure() throw()
5236ac495dSmrg   { }
5336ac495dSmrg 
5436ac495dSmrg   const char*
what() const5536ac495dSmrg   ios_base::failure::what() const throw()
5636ac495dSmrg   { return _M_msg.c_str(); }
5736ac495dSmrg 
5836ac495dSmrg #if _GLIBCXX_USE_DUAL_ABI
5936ac495dSmrg   // When the dual ABI is enabled __throw_ios_failure() is defined in
6036ac495dSmrg   // src/c++11/cxx11-ios_failure.cc
6136ac495dSmrg #if __cpp_rtti
6236ac495dSmrg   // If RTTI is enabled the exception type thrown will use these functions to
6336ac495dSmrg   // construct/destroy a gcc4-compatible ios::failure object in a buffer,
6436ac495dSmrg   // and to catch that object via a handler of the gcc4-compatible type.
6536ac495dSmrg   void
__construct_ios_failure(void * buf,const char * msg)6636ac495dSmrg   __construct_ios_failure(void* buf, const char* msg)
6736ac495dSmrg   { ::new(buf) ios_base::failure(msg); }
6836ac495dSmrg 
6936ac495dSmrg   void
__destroy_ios_failure(void * buf)7036ac495dSmrg   __destroy_ios_failure(void* buf)
7136ac495dSmrg   { static_cast<ios_base::failure*>(buf)->~failure(); }
7236ac495dSmrg 
7336ac495dSmrg   bool
__is_ios_failure_handler(const __cxxabiv1::__class_type_info * type)7436ac495dSmrg   __is_ios_failure_handler(const __cxxabiv1::__class_type_info* type)
7536ac495dSmrg   { return *type == typeid(ios::failure); }
7636ac495dSmrg 
7736ac495dSmrg   namespace {
7836ac495dSmrg   // C++98-style static assertions to ensure ios::failure fits in a buffer
7936ac495dSmrg   // with the same size and alignment as runtime_error:
8036ac495dSmrg   typedef char S[1 / (sizeof(ios::failure) <= sizeof(runtime_error))];
8136ac495dSmrg   typedef char A[1 / (__alignof(ios::failure) <= __alignof(runtime_error))];
8236ac495dSmrg   }
8336ac495dSmrg #endif // __cpp_rtti
8436ac495dSmrg 
8536ac495dSmrg #else // ! _GLIBCXX_USE_DUAL_ABI
8636ac495dSmrg 
8736ac495dSmrg   void
__throw_ios_failure(const char * __s)8836ac495dSmrg   __throw_ios_failure(const char* __s __attribute__((unused)))
8936ac495dSmrg   { _GLIBCXX_THROW_OR_ABORT(ios::failure(_(__s))); }
9036ac495dSmrg 
91c0a68be4Smrg   void
__throw_ios_failure(const char * str,int)92c0a68be4Smrg   __throw_ios_failure(const char* str, int)
93c0a68be4Smrg   { __throw_ios_failure(str); }
94c0a68be4Smrg 
95c0a68be4Smrg #endif // _GLIBCXX_USE_DUAL_ABI
9636ac495dSmrg 
9736ac495dSmrg _GLIBCXX_END_NAMESPACE_VERSION
9836ac495dSmrg } // namespace
99