libstdc++
stdexcept_throwfwd.h
Go to the documentation of this file.
1// Function-Based Exception Support -*- C++ -*-
2
3// Copyright (C) 2001-2025 Free Software Foundation, Inc.
4//
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)
9// any later version.
10
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.
15
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.
19
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/>.
24
25/** @file bits/stdexcept_throwfwd.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{stdexcept}
28 */
29
30//
31// ISO C++ 14882: 19.1 Exception classes
32//
33
34#ifndef _STDEXCEPT_THROWFWD_H
35#define _STDEXCEPT_THROWFWD_H 1
36
37#include <bits/c++config.h>
39
40namespace std _GLIBCXX_VISIBILITY(default)
41{
42_GLIBCXX_BEGIN_NAMESPACE_VERSION
43
44#if _GLIBCXX_HOSTED
45#if (__cpp_exceptions && __cplusplus > 202302L \
46 && __cpp_constexpr_exceptions >= 202411L)
47 // Helper for exception objects in <stdexcept>
48 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
49 __throw_logic_error(const char*);
50 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
51 __throw_domain_error(const char*);
52 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
53 __throw_invalid_argument(const char*);
54 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
55 __throw_length_error(const char*);
56 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
57 __throw_out_of_range(const char*);
58 template <typename... _Args>
59 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
60 __throw_out_of_range_fmt(const char* __s, _Args... __args);
61 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
62 __throw_runtime_error(const char*);
63 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
64 __throw_overflow_error(const char*);
65 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
66 __throw_underflow_error(const char*);
67#else
68 // Helpers for exception objects in <stdexcept>
69 void
70 __throw_logic_error(const char*) __attribute__((__noreturn__,__cold__));
71
72 void
73 __throw_domain_error(const char*) __attribute__((__noreturn__,__cold__));
74
75 void
76 __throw_invalid_argument(const char*) __attribute__((__noreturn__,__cold__));
77
78 void
79 __throw_length_error(const char*) __attribute__((__noreturn__,__cold__));
80
81 void
82 __throw_out_of_range(const char*) __attribute__((__noreturn__,__cold__));
83
84 void
85 __throw_out_of_range_fmt(const char*, ...)
86 __attribute__((__noreturn__,__cold__,__format__(__gnu_printf__, 1, 2)));
87
88 void
89 __throw_runtime_error(const char*) __attribute__((__noreturn__,__cold__));
90
91 void
92 __throw_overflow_error(const char*) __attribute__((__noreturn__,__cold__));
93
94 void
95 __throw_underflow_error(const char*) __attribute__((__noreturn__,__cold__));
96#endif
97
98#else // ! HOSTED
99
100 __attribute__((__noreturn__)) inline void
101 __throw_invalid_argument(const char*)
102 { std::__terminate(); }
103
104 __attribute__((__noreturn__)) inline void
105 __throw_out_of_range(const char*)
106 { std::__terminate(); }
107
108 __attribute__((__noreturn__)) inline void
109 __throw_out_of_range_fmt(const char*, ...)
110 { std::__terminate(); }
111
112 __attribute__((__noreturn__)) inline void
113 __throw_runtime_error(const char*)
114 { std::__terminate(); }
115
116 __attribute__((__noreturn__)) inline void
117 __throw_overflow_error(const char*)
118 { std::__terminate(); }
119
120#endif // HOSTED
121
122_GLIBCXX_END_NAMESPACE_VERSION
123} // namespace
124
125#endif
ISO C++ entities toplevel namespace is std.