1// Copyright (C) 2001-2015 Free Software Foundation, Inc.
2//
3// This file is part of the GNU ISO C++ Library.  This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// Under Section 7 of GPL version 3, you are granted additional
15// permissions described in the GCC Runtime Library Exception, version
16// 3.1, as published by the Free Software Foundation.
17
18// You should have received a copy of the GNU General Public License and
19// a copy of the GCC Runtime Library Exception along with this program;
20// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
21// <http://www.gnu.org/licenses/>.
22
23// We don't want to change the type thrown by __throw_ios_failure (yet?)
24#define _GLIBCXX_USE_CXX11_ABI 0
25
26#include <bits/functexcept.h>
27#include <cstdlib>
28#include <exception>
29#include <stdexcept>
30#include <new>
31#include <typeinfo>
32#include <ios>
33#include <system_error>
34#include <future>
35#include <functional>
36#include <bits/regex_error.h>
37#include <stdarg.h>
38
39#ifdef _GLIBCXX_USE_NLS
40# include <libintl.h>
41# define _(msgid)   gettext (msgid)
42#else
43# define _(msgid)   (msgid)
44#endif
45
46namespace __gnu_cxx
47{
48  int __snprintf_lite(char *__buf, size_t __bufsize, const char *__fmt,
49		      va_list __ap);
50}
51
52namespace std _GLIBCXX_VISIBILITY(default)
53{
54_GLIBCXX_BEGIN_NAMESPACE_VERSION
55
56  void
57  __throw_bad_exception()
58  { _GLIBCXX_THROW_OR_ABORT(bad_exception()); }
59
60  void
61  __throw_bad_alloc()
62  { _GLIBCXX_THROW_OR_ABORT(bad_alloc()); }
63
64  void
65  __throw_bad_cast()
66  { _GLIBCXX_THROW_OR_ABORT(bad_cast()); }
67
68  void
69  __throw_bad_typeid()
70  { _GLIBCXX_THROW_OR_ABORT(bad_typeid()); }
71
72  void
73  __throw_logic_error(const char* __s __attribute__((unused)))
74  { _GLIBCXX_THROW_OR_ABORT(logic_error(_(__s))); }
75
76  void
77  __throw_domain_error(const char* __s __attribute__((unused)))
78  { _GLIBCXX_THROW_OR_ABORT(domain_error(_(__s))); }
79
80  void
81  __throw_invalid_argument(const char* __s __attribute__((unused)))
82  { _GLIBCXX_THROW_OR_ABORT(invalid_argument(_(__s))); }
83
84  void
85  __throw_length_error(const char* __s __attribute__((unused)))
86  { _GLIBCXX_THROW_OR_ABORT(length_error(_(__s))); }
87
88  void
89  __throw_out_of_range(const char* __s __attribute__((unused)))
90  { _GLIBCXX_THROW_OR_ABORT(out_of_range(_(__s))); }
91
92  void
93  __throw_out_of_range_fmt(const char* __fmt, ...)
94  {
95    const size_t __len = __builtin_strlen(__fmt);
96    // We expect at most 2 numbers, and 1 short string. The additional
97    // 512 bytes should provide more than enough space for expansion.
98    const size_t __alloca_size = __len + 512;
99    char *const __s = static_cast<char*>(__builtin_alloca(__alloca_size));
100    va_list __ap;
101
102    va_start(__ap, __fmt);
103    __gnu_cxx::__snprintf_lite(__s, __alloca_size, __fmt, __ap);
104    _GLIBCXX_THROW_OR_ABORT(out_of_range(_(__s)));
105    va_end(__ap);  // Not reached.
106  }
107
108  void
109  __throw_runtime_error(const char* __s __attribute__((unused)))
110  { _GLIBCXX_THROW_OR_ABORT(runtime_error(_(__s))); }
111
112  void
113  __throw_range_error(const char* __s __attribute__((unused)))
114  { _GLIBCXX_THROW_OR_ABORT(range_error(_(__s))); }
115
116  void
117  __throw_overflow_error(const char* __s __attribute__((unused)))
118  { _GLIBCXX_THROW_OR_ABORT(overflow_error(_(__s))); }
119
120  void
121  __throw_underflow_error(const char* __s __attribute__((unused)))
122  { _GLIBCXX_THROW_OR_ABORT(underflow_error(_(__s))); }
123
124  void
125  __throw_ios_failure(const char* __s __attribute__((unused)))
126  { _GLIBCXX_THROW_OR_ABORT(ios_base::failure(_(__s))); }
127
128  void
129  __throw_system_error(int __i __attribute__((unused)))
130  { _GLIBCXX_THROW_OR_ABORT(system_error(error_code(__i,
131						    generic_category()))); }
132
133  void
134  __throw_future_error(int __i __attribute__((unused)))
135  { _GLIBCXX_THROW_OR_ABORT(future_error(make_error_code(future_errc(__i)))); }
136
137  void
138  __throw_bad_function_call()
139  { _GLIBCXX_THROW_OR_ABORT(bad_function_call()); }
140
141  void
142  __throw_regex_error(regex_constants::error_type __ecode
143		      __attribute__((unused)))
144  { _GLIBCXX_THROW_OR_ABORT(regex_error(__ecode)); }
145
146_GLIBCXX_END_NAMESPACE_VERSION
147} // namespace
148