1 // Methods for Exception Support for -*- C++ -*-
3 // Copyright (C) 2014-2015 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
26 // ISO C++ 14882: 19.1 Exception classes
29 // All exception classes still use the classic COW std::string.
30 #define _GLIBCXX_USE_CXX11_ABI 0
31 #define _GLIBCXX_DEFINE_STDEXCEPT_COPY_OPS 1
32 #define __cow_string __cow_stringxxx
34 #include <system_error>
37 namespace std
_GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
41 // Copy constructors and assignment operators defined using COW std::string
43 logic_error::logic_error(const logic_error
& e
) noexcept
44 : _M_msg(e
._M_msg
) { }
46 logic_error
& logic_error::operator=(const logic_error
& e
) noexcept
47 { _M_msg
= e
._M_msg
; return *this; }
49 runtime_error::runtime_error(const runtime_error
& e
) noexcept
50 : _M_msg(e
._M_msg
) { }
53 runtime_error::operator=(const runtime_error
& e
) noexcept
54 { _M_msg
= e
._M_msg
; return *this; }
56 // New C++11 constructors:
58 logic_error::logic_error(const char* __arg
)
59 : exception(), _M_msg(__arg
) { }
61 domain_error::domain_error(const char* __arg
)
62 : logic_error(__arg
) { }
64 invalid_argument::invalid_argument(const char* __arg
)
65 : logic_error(__arg
) { }
67 length_error::length_error(const char* __arg
)
68 : logic_error(__arg
) { }
70 out_of_range::out_of_range(const char* __arg
)
71 : logic_error(__arg
) { }
73 runtime_error::runtime_error(const char* __arg
)
74 : exception(), _M_msg(__arg
) { }
76 range_error::range_error(const char* __arg
)
77 : runtime_error(__arg
) { }
79 overflow_error::overflow_error(const char* __arg
)
80 : runtime_error(__arg
) { }
82 underflow_error::underflow_error(const char* __arg
)
83 : runtime_error(__arg
) { }
85 #if _GLIBCXX_USE_DUAL_ABI
86 // Converting constructor from COW std::string to SSO string.
87 __sso_string::__sso_string(const string
& s
)
88 : __sso_string(s
.c_str(), s
.length()) { }
90 // Redefine __cow_string so that we can define and export its members
91 // in terms of the COW std::string.
96 char _M_bytes
[sizeof(_M_p
)];
101 __cow_string(const std::string
& s
);
102 __cow_string(const char*, size_t n
);
103 __cow_string(const __cow_string
&) noexcept
;
104 __cow_string
& operator=(const __cow_string
&) noexcept
;
106 __cow_string(__cow_string
&&) noexcept
;
107 __cow_string
& operator=(__cow_string
&&) noexcept
;
110 __cow_string::__cow_string() : _M_str() { }
112 __cow_string::__cow_string(const std::string
& s
) : _M_str(s
) { }
114 __cow_string::__cow_string(const char* s
, size_t n
) : _M_str(s
, n
) { }
116 __cow_string::__cow_string(const __cow_string
& s
) noexcept
117 : _M_str(s
._M_str
) { }
120 __cow_string::operator=(const __cow_string
& s
) noexcept
126 __cow_string::~__cow_string() { _M_str
.~basic_string(); }
128 __cow_string::__cow_string(__cow_string
&& s
) noexcept
129 : _M_str(std::move(s
._M_str
)) { }
132 __cow_string::operator=(__cow_string
&& s
) noexcept
134 _M_str
= std::move(s
._M_str
);
138 static_assert(sizeof(__cow_string
) == sizeof(std::string
),
139 "sizeof(std::string) has changed");
140 static_assert(alignof(__cow_string
) == alignof(std::string
),
141 "alignof(std::string) has changed");
144 // Return error_category::message() as an SSO string
146 error_category::_M_message(int i
) const
148 string msg
= this->message(i
);
149 return {msg
.c_str(), msg
.length()};
152 _GLIBCXX_END_NAMESPACE_VERSION