brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.2 KiB · 85e1162 Raw
293 lines · plain
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP_STDEXCEPT11#define _LIBCPP_STDEXCEPT12 13/*14    stdexcept synopsis15 16namespace std17{18 19class logic_error;20class domain_error;21class invalid_argument;22class length_error;23class out_of_range;24class runtime_error;25class range_error;26class overflow_error;27class underflow_error;28 29for each class xxx_error:30 31class xxx_error : public exception // at least indirectly32{33public:34    explicit xxx_error(const string& what_arg);35    explicit xxx_error(const char*   what_arg);36 37    virtual const char* what() const noexcept // returns what_arg38};39 40}  // std41 42*/43 44#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)45#  include <__cxx03/stdexcept>46#else47#  include <__config>48#  include <__exception/exception.h>49#  include <__fwd/string.h>50#  include <__verbose_abort>51 52#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)53#    pragma GCC system_header54#  endif55 56_LIBCPP_BEGIN_NAMESPACE_STD57 58#  ifndef _LIBCPP_ABI_VCRUNTIME59class _LIBCPP_HIDDEN __libcpp_refstring {60  const char* __imp_;61 62  bool __uses_refcount() const;63 64public:65  explicit __libcpp_refstring(const char* __msg);66  __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;67  __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;68  ~__libcpp_refstring();69 70  _LIBCPP_HIDE_FROM_ABI const char* c_str() const _NOEXCEPT { return __imp_; }71};72#  endif // !_LIBCPP_ABI_VCRUNTIME73 74_LIBCPP_END_NAMESPACE_STD75 76namespace std // purposefully not using versioning namespace77{78 79class _LIBCPP_EXPORTED_FROM_ABI logic_error : public exception {80#  ifndef _LIBCPP_ABI_VCRUNTIME81 82private:83  std::__libcpp_refstring __imp_;84 85public:86  explicit logic_error(const string&);87  explicit logic_error(const char*);88 89  logic_error(const logic_error&) _NOEXCEPT;90  logic_error& operator=(const logic_error&) _NOEXCEPT;91 92  ~logic_error() _NOEXCEPT override;93 94  const char* what() const _NOEXCEPT override;95#  else96 97public:98  explicit logic_error(const std::string&); // Symbol uses versioned std::string99  _LIBCPP_HIDE_FROM_ABI explicit logic_error(const char* __s) : exception(__s) {}100#  endif101};102 103class _LIBCPP_EXPORTED_FROM_ABI runtime_error : public exception {104#  ifndef _LIBCPP_ABI_VCRUNTIME105 106private:107  std::__libcpp_refstring __imp_;108 109public:110  explicit runtime_error(const string&);111  explicit runtime_error(const char*);112 113  runtime_error(const runtime_error&) _NOEXCEPT;114  runtime_error& operator=(const runtime_error&) _NOEXCEPT;115 116  ~runtime_error() _NOEXCEPT override;117 118  const char* what() const _NOEXCEPT override;119#  else120 121public:122  explicit runtime_error(const std::string&); // Symbol uses versioned std::string123  _LIBCPP_HIDE_FROM_ABI explicit runtime_error(const char* __s) : exception(__s) {}124#  endif // _LIBCPP_ABI_VCRUNTIME125};126 127class _LIBCPP_EXPORTED_FROM_ABI domain_error : public logic_error {128public:129  _LIBCPP_HIDE_FROM_ABI explicit domain_error(const string& __s) : logic_error(__s) {}130  _LIBCPP_HIDE_FROM_ABI explicit domain_error(const char* __s) : logic_error(__s) {}131 132#  ifndef _LIBCPP_ABI_VCRUNTIME133  _LIBCPP_HIDE_FROM_ABI domain_error(const domain_error&) _NOEXCEPT            = default;134  _LIBCPP_HIDE_FROM_ABI domain_error& operator=(const domain_error&) _NOEXCEPT = default;135  ~domain_error() _NOEXCEPT override;136#  endif137};138 139class _LIBCPP_EXPORTED_FROM_ABI invalid_argument : public logic_error {140public:141  _LIBCPP_HIDE_FROM_ABI explicit invalid_argument(const string& __s) : logic_error(__s) {}142  _LIBCPP_HIDE_FROM_ABI explicit invalid_argument(const char* __s) : logic_error(__s) {}143 144#  ifndef _LIBCPP_ABI_VCRUNTIME145  _LIBCPP_HIDE_FROM_ABI invalid_argument(const invalid_argument&) _NOEXCEPT            = default;146  _LIBCPP_HIDE_FROM_ABI invalid_argument& operator=(const invalid_argument&) _NOEXCEPT = default;147  ~invalid_argument() _NOEXCEPT override;148#  endif149};150 151class _LIBCPP_EXPORTED_FROM_ABI length_error : public logic_error {152public:153  _LIBCPP_HIDE_FROM_ABI explicit length_error(const string& __s) : logic_error(__s) {}154  _LIBCPP_HIDE_FROM_ABI explicit length_error(const char* __s) : logic_error(__s) {}155#  ifndef _LIBCPP_ABI_VCRUNTIME156  _LIBCPP_HIDE_FROM_ABI length_error(const length_error&) _NOEXCEPT            = default;157  _LIBCPP_HIDE_FROM_ABI length_error& operator=(const length_error&) _NOEXCEPT = default;158  ~length_error() _NOEXCEPT override;159#  endif160};161 162class _LIBCPP_EXPORTED_FROM_ABI out_of_range : public logic_error {163public:164  _LIBCPP_HIDE_FROM_ABI explicit out_of_range(const string& __s) : logic_error(__s) {}165  _LIBCPP_HIDE_FROM_ABI explicit out_of_range(const char* __s) : logic_error(__s) {}166 167#  ifndef _LIBCPP_ABI_VCRUNTIME168  _LIBCPP_HIDE_FROM_ABI out_of_range(const out_of_range&) _NOEXCEPT            = default;169  _LIBCPP_HIDE_FROM_ABI out_of_range& operator=(const out_of_range&) _NOEXCEPT = default;170  ~out_of_range() _NOEXCEPT override;171#  endif172};173 174class _LIBCPP_EXPORTED_FROM_ABI range_error : public runtime_error {175public:176  _LIBCPP_HIDE_FROM_ABI explicit range_error(const string& __s) : runtime_error(__s) {}177  _LIBCPP_HIDE_FROM_ABI explicit range_error(const char* __s) : runtime_error(__s) {}178 179#  ifndef _LIBCPP_ABI_VCRUNTIME180  _LIBCPP_HIDE_FROM_ABI range_error(const range_error&) _NOEXCEPT            = default;181  _LIBCPP_HIDE_FROM_ABI range_error& operator=(const range_error&) _NOEXCEPT = default;182  ~range_error() _NOEXCEPT override;183#  endif184};185 186class _LIBCPP_EXPORTED_FROM_ABI overflow_error : public runtime_error {187public:188  _LIBCPP_HIDE_FROM_ABI explicit overflow_error(const string& __s) : runtime_error(__s) {}189  _LIBCPP_HIDE_FROM_ABI explicit overflow_error(const char* __s) : runtime_error(__s) {}190 191#  ifndef _LIBCPP_ABI_VCRUNTIME192  _LIBCPP_HIDE_FROM_ABI overflow_error(const overflow_error&) _NOEXCEPT            = default;193  _LIBCPP_HIDE_FROM_ABI overflow_error& operator=(const overflow_error&) _NOEXCEPT = default;194  ~overflow_error() _NOEXCEPT override;195#  endif196};197 198class _LIBCPP_EXPORTED_FROM_ABI underflow_error : public runtime_error {199public:200  _LIBCPP_HIDE_FROM_ABI explicit underflow_error(const string& __s) : runtime_error(__s) {}201  _LIBCPP_HIDE_FROM_ABI explicit underflow_error(const char* __s) : runtime_error(__s) {}202 203#  ifndef _LIBCPP_ABI_VCRUNTIME204  _LIBCPP_HIDE_FROM_ABI underflow_error(const underflow_error&) _NOEXCEPT            = default;205  _LIBCPP_HIDE_FROM_ABI underflow_error& operator=(const underflow_error&) _NOEXCEPT = default;206  ~underflow_error() _NOEXCEPT override;207#  endif208};209 210} // namespace std211 212_LIBCPP_BEGIN_NAMESPACE_STD213 214// in the dylib215[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_runtime_error(const char*);216 217[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_logic_error(const char* __msg) {218#  if _LIBCPP_HAS_EXCEPTIONS219  throw logic_error(__msg);220#  else221  _LIBCPP_VERBOSE_ABORT("logic_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);222#  endif223}224 225[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_domain_error(const char* __msg) {226#  if _LIBCPP_HAS_EXCEPTIONS227  throw domain_error(__msg);228#  else229  _LIBCPP_VERBOSE_ABORT("domain_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);230#  endif231}232 233[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_invalid_argument(const char* __msg) {234#  if _LIBCPP_HAS_EXCEPTIONS235  throw invalid_argument(__msg);236#  else237  _LIBCPP_VERBOSE_ABORT("invalid_argument was thrown in -fno-exceptions mode with message \"%s\"", __msg);238#  endif239}240 241[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_length_error(const char* __msg) {242#  if _LIBCPP_HAS_EXCEPTIONS243  throw length_error(__msg);244#  else245  _LIBCPP_VERBOSE_ABORT("length_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);246#  endif247}248 249[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range(const char* __msg) {250#  if _LIBCPP_HAS_EXCEPTIONS251  throw out_of_range(__msg);252#  else253  _LIBCPP_VERBOSE_ABORT("out_of_range was thrown in -fno-exceptions mode with message \"%s\"", __msg);254#  endif255}256 257[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_range_error(const char* __msg) {258#  if _LIBCPP_HAS_EXCEPTIONS259  throw range_error(__msg);260#  else261  _LIBCPP_VERBOSE_ABORT("range_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);262#  endif263}264 265[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_overflow_error(const char* __msg) {266#  if _LIBCPP_HAS_EXCEPTIONS267  throw overflow_error(__msg);268#  else269  _LIBCPP_VERBOSE_ABORT("overflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);270#  endif271}272 273[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_underflow_error(const char* __msg) {274#  if _LIBCPP_HAS_EXCEPTIONS275  throw underflow_error(__msg);276#  else277  _LIBCPP_VERBOSE_ABORT("underflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);278#  endif279}280 281_LIBCPP_END_NAMESPACE_STD282 283#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20284#    include <cstddef>285#    include <cstdlib>286#    include <exception>287#    include <iosfwd>288#    include <new>289#  endif290#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)291 292#endif // _LIBCPP_STDEXCEPT293