2014-03-14 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libstdc++-v3 / src / c++11 / functexcept.cc
blobd184bfc0b6c36a44a0183e6758cc64d93eab4234
1 // Copyright (C) 2001-2014 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.
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.
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.
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/>.
23 #include <bits/functexcept.h>
24 #include <cstdlib>
25 #include <exception>
26 #include <stdexcept>
27 #include <new>
28 #include <typeinfo>
29 #include <ios>
30 #include <system_error>
31 #include <future>
32 #include <functional>
33 #include <bits/regex_error.h>
34 #include <stdarg.h>
36 #ifdef _GLIBCXX_USE_NLS
37 # include <libintl.h>
38 # define _(msgid) gettext (msgid)
39 #else
40 # define _(msgid) (msgid)
41 #endif
43 namespace __gnu_cxx
45 int __snprintf_lite(char *__buf, size_t __bufsize, const char *__fmt,
46 va_list __ap);
49 namespace std _GLIBCXX_VISIBILITY(default)
51 _GLIBCXX_BEGIN_NAMESPACE_VERSION
53 void
54 __throw_bad_exception()
55 { _GLIBCXX_THROW_OR_ABORT(bad_exception()); }
57 void
58 __throw_bad_alloc()
59 { _GLIBCXX_THROW_OR_ABORT(bad_alloc()); }
61 void
62 __throw_bad_cast()
63 { _GLIBCXX_THROW_OR_ABORT(bad_cast()); }
65 void
66 __throw_bad_typeid()
67 { _GLIBCXX_THROW_OR_ABORT(bad_typeid()); }
69 void
70 __throw_logic_error(const char* __s __attribute__((unused)))
71 { _GLIBCXX_THROW_OR_ABORT(logic_error(_(__s))); }
73 void
74 __throw_domain_error(const char* __s __attribute__((unused)))
75 { _GLIBCXX_THROW_OR_ABORT(domain_error(_(__s))); }
77 void
78 __throw_invalid_argument(const char* __s __attribute__((unused)))
79 { _GLIBCXX_THROW_OR_ABORT(invalid_argument(_(__s))); }
81 void
82 __throw_length_error(const char* __s __attribute__((unused)))
83 { _GLIBCXX_THROW_OR_ABORT(length_error(_(__s))); }
85 void
86 __throw_out_of_range(const char* __s __attribute__((unused)))
87 { _GLIBCXX_THROW_OR_ABORT(out_of_range(_(__s))); }
89 void
90 __throw_out_of_range_fmt(const char* __fmt, ...)
92 const size_t __len = __builtin_strlen(__fmt);
93 // We expect at most 2 numbers, and 1 short string. The additional
94 // 512 bytes should provide more than enough space for expansion.
95 const size_t __alloca_size = __len + 512;
96 char *const __s = static_cast<char*>(__builtin_alloca(__alloca_size));
97 va_list __ap;
99 va_start(__ap, __fmt);
100 __gnu_cxx::__snprintf_lite(__s, __alloca_size, __fmt, __ap);
101 _GLIBCXX_THROW_OR_ABORT(out_of_range(_(__s)));
102 va_end(__ap); // Not reached.
105 void
106 __throw_runtime_error(const char* __s __attribute__((unused)))
107 { _GLIBCXX_THROW_OR_ABORT(runtime_error(_(__s))); }
109 void
110 __throw_range_error(const char* __s __attribute__((unused)))
111 { _GLIBCXX_THROW_OR_ABORT(range_error(_(__s))); }
113 void
114 __throw_overflow_error(const char* __s __attribute__((unused)))
115 { _GLIBCXX_THROW_OR_ABORT(overflow_error(_(__s))); }
117 void
118 __throw_underflow_error(const char* __s __attribute__((unused)))
119 { _GLIBCXX_THROW_OR_ABORT(underflow_error(_(__s))); }
121 void
122 __throw_ios_failure(const char* __s __attribute__((unused)))
123 { _GLIBCXX_THROW_OR_ABORT(ios_base::failure(_(__s))); }
125 void
126 __throw_system_error(int __i __attribute__((unused)))
127 { _GLIBCXX_THROW_OR_ABORT(system_error(error_code(__i,
128 generic_category()))); }
130 void
131 __throw_future_error(int __i __attribute__((unused)))
132 { _GLIBCXX_THROW_OR_ABORT(future_error(make_error_code(future_errc(__i)))); }
134 void
135 __throw_bad_function_call()
136 { _GLIBCXX_THROW_OR_ABORT(bad_function_call()); }
138 void
139 __throw_regex_error(regex_constants::error_type __ecode
140 __attribute__((unused)))
141 { _GLIBCXX_THROW_OR_ABORT(regex_error(__ecode)); }
143 _GLIBCXX_END_NAMESPACE_VERSION
144 } // namespace