Fix ifunc detection in target-supports.exp file.
[official-gcc.git] / libstdc++-v3 / src / c++11 / compatibility-c++0x.cc
blob08789dce8bccd2bebfde8f474ab932f304a8c3b4
1 // Compatibility symbols for previous versions, C++0x bits -*- C++ -*-
3 // Copyright (C) 2009-2018 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.
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/>.
25 #define _GLIBCXX_COMPATIBILITY_CXX0X
26 #define _GLIBCXX_USE_CXX11_ABI 0
27 #define error_category error_categoryxx
28 #define system_category system_categoryxx
29 #define generic_category generic_categoryxx
30 #define _V2 _V2xx
31 #include <string>
32 #include <system_error>
33 #include <cstring>
34 #undef error_category
35 #undef system_category
36 #undef generic_category
37 #undef _V2
39 #if __cplusplus < 201103L
40 # error "compatibility-c++0x.cc must be compiled with -std=gnu++0x"
41 #endif
43 #ifdef _GLIBCXX_SHARED
45 namespace std _GLIBCXX_VISIBILITY(default)
47 _GLIBCXX_BEGIN_NAMESPACE_VERSION
49 // gcc-4.4.0
50 // <mutex> exported std::lock_error
51 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
52 class lock_error : public exception
54 public:
55 virtual const char*
56 _GLIBCXX_CONST what() const throw();
59 const char*
60 lock_error::what() const throw()
61 { return "std::lock_error"; }
62 #endif
64 // We need these due to the symbols exported since GLIBCXX_3.4.10.
65 // See libstdc++/41662 for details.
67 #ifndef _GLIBCXX_LONG_DOUBLE_COMPAT_IMPL
68 template<>
69 struct hash<string>
71 size_t operator()(string) const;
74 size_t
75 hash<string>::operator()(string __s) const
76 { return _Hash_impl::hash(__s.data(), __s.length()); }
78 template<>
79 struct hash<const string&>
81 size_t operator()(const string&) const;
84 size_t
85 hash<const string&>::operator()(const string& __s) const
86 { return _Hash_impl::hash(__s.data(), __s.length()); }
88 #ifdef _GLIBCXX_USE_WCHAR_T
89 template<>
90 struct hash<wstring>
92 size_t operator()(wstring) const;
95 size_t
96 hash<wstring>::operator()(wstring __s) const
97 { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
99 template<>
100 struct hash<const wstring&>
102 size_t operator()(const wstring&) const;
105 size_t
106 hash<const wstring&>::operator()(const wstring& __s) const
107 { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
108 #endif
109 #endif
111 template<>
112 struct hash<error_code>
114 size_t operator()(error_code) const;
117 size_t
118 hash<error_code>::operator()(error_code __e) const
120 const size_t __tmp = std::_Hash_impl::hash(__e._M_value);
121 return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp);
124 // gcc-4.7.0
125 // <chrono> changes is_monotonic to is_steady.
126 namespace chrono
128 struct system_clock
130 static constexpr bool is_monotonic = false;
132 constexpr bool system_clock::is_monotonic;
133 } // namespace chrono
135 // gcc-5 replaces this with _V2::error_category
136 class error_category
138 public:
139 error_category() noexcept;
141 virtual ~error_category();
143 error_category(const error_category&) = delete;
144 error_category& operator=(const error_category&) = delete;
146 virtual const char*
147 name() const noexcept = 0;
149 virtual string
150 message(int) const = 0;
152 virtual error_condition
153 default_error_condition(int __i) const noexcept;
155 virtual bool
156 equivalent(int __i, const error_condition& __cond) const noexcept;
158 virtual bool
159 equivalent(const error_code& __code, int __i) const noexcept;
161 bool
162 operator<(const error_category& __other) const noexcept
163 { return less<const error_category*>()(this, &__other); }
165 bool
166 operator==(const error_category& __other) const noexcept
167 { return this == &__other; }
169 bool
170 operator!=(const error_category& __other) const noexcept
171 { return this != &__other; }
174 // gcc-4.9.0
175 // LWG 2145 changes this constructor to constexpr i.e. inline
176 error_category::error_category() noexcept = default;
178 error_category::~error_category() noexcept = default;
180 namespace
182 using std::string;
184 struct generic_error_category : public std::error_category
186 virtual const char*
187 name() const noexcept
188 { return "generic"; }
190 virtual string
191 message(int i) const
193 // XXX locale issues: how does one get or set loc.
194 // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc)
195 return string(strerror(i));
199 struct system_error_category : public std::error_category
201 virtual const char*
202 name() const noexcept
203 { return "system"; }
205 virtual string
206 message(int i) const
208 // XXX locale issues: how does one get or set loc.
209 // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc)
210 return string(strerror(i));
214 const generic_error_category generic_category_instance{};
215 const system_error_category system_category_instance{};
218 const error_category&
219 system_category() noexcept { return system_category_instance; }
221 const error_category&
222 generic_category() noexcept { return generic_category_instance; }
224 namespace _V2
226 _GLIBCXX_CONST const error_categoryxx& system_category() noexcept;
227 _GLIBCXX_CONST const error_categoryxx& generic_category() noexcept;
230 error_condition
231 error_category::default_error_condition(int __i) const noexcept
233 if (*this == system_category())
234 return error_condition(__i, _V2::system_category());
235 return error_condition(__i, _V2::generic_category());
238 bool
239 error_category::equivalent(int __i,
240 const error_condition& __cond) const noexcept
241 { return default_error_condition(__i) == __cond; }
243 bool
244 error_category::equivalent(const error_code& __code, int __i) const noexcept
246 if (*this == system_category()
247 && __code.category() == _V2::system_category())
248 return __code.value() == __i;
249 if (*this == generic_category()
250 && __code.category() == _V2::generic_category())
251 return __code.value() == __i;
252 return false;
255 _GLIBCXX_END_NAMESPACE_VERSION
257 #endif