Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:26

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___EXCEPTION_EXCEPTION_H
0010 #define _LIBCPP___CXX03___EXCEPTION_EXCEPTION_H
0011 
0012 #include <__cxx03/__config>
0013 
0014 // <vcruntime_exception.h> defines its own std::exception and std::bad_exception types,
0015 // which we use in order to be ABI-compatible with other STLs on Windows.
0016 #if defined(_LIBCPP_ABI_VCRUNTIME)
0017 #  include <__cxx03/vcruntime_exception.h>
0018 #endif
0019 
0020 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0021 #  pragma GCC system_header
0022 #endif
0023 
0024 namespace std { // purposefully not using versioning namespace
0025 
0026 #if defined(_LIBCPP_ABI_VCRUNTIME) && (!defined(_HAS_EXCEPTIONS) || _HAS_EXCEPTIONS != 0)
0027 // The std::exception class was already included above, but we're explicit about this condition here for clarity.
0028 
0029 #elif defined(_LIBCPP_ABI_VCRUNTIME) && _HAS_EXCEPTIONS == 0
0030 // However, <vcruntime_exception.h> does not define std::exception and std::bad_exception
0031 // when _HAS_EXCEPTIONS == 0.
0032 //
0033 // Since libc++ still wants to provide the std::exception hierarchy even when _HAS_EXCEPTIONS == 0
0034 // (after all those are simply types like any other), we define an ABI-compatible version
0035 // of the VCRuntime std::exception and std::bad_exception types in that mode.
0036 
0037 struct __std_exception_data {
0038   char const* _What;
0039   bool _DoFree;
0040 };
0041 
0042 class exception { // base of all library exceptions
0043 public:
0044   exception() _NOEXCEPT : __data_() {}
0045 
0046   explicit exception(char const* __message) _NOEXCEPT : __data_() {
0047     __data_._What   = __message;
0048     __data_._DoFree = true;
0049   }
0050 
0051   exception(exception const&) _NOEXCEPT {}
0052 
0053   exception& operator=(exception const&) _NOEXCEPT { return *this; }
0054 
0055   virtual ~exception() _NOEXCEPT {}
0056 
0057   virtual char const* what() const _NOEXCEPT { return __data_._What ? __data_._What : "Unknown exception"; }
0058 
0059 private:
0060   __std_exception_data __data_;
0061 };
0062 
0063 class bad_exception : public exception {
0064 public:
0065   bad_exception() _NOEXCEPT : exception("bad exception") {}
0066 };
0067 
0068 #else  // !defined(_LIBCPP_ABI_VCRUNTIME)
0069 // On all other platforms, we define our own std::exception and std::bad_exception types
0070 // regardless of whether exceptions are turned on as a language feature.
0071 
0072 class _LIBCPP_EXPORTED_FROM_ABI exception {
0073 public:
0074   _LIBCPP_HIDE_FROM_ABI exception() _NOEXCEPT {}
0075   _LIBCPP_HIDE_FROM_ABI exception(const exception&) _NOEXCEPT            = default;
0076   _LIBCPP_HIDE_FROM_ABI exception& operator=(const exception&) _NOEXCEPT = default;
0077 
0078   virtual ~exception() _NOEXCEPT;
0079   virtual const char* what() const _NOEXCEPT;
0080 };
0081 
0082 class _LIBCPP_EXPORTED_FROM_ABI bad_exception : public exception {
0083 public:
0084   _LIBCPP_HIDE_FROM_ABI bad_exception() _NOEXCEPT {}
0085   _LIBCPP_HIDE_FROM_ABI bad_exception(const bad_exception&) _NOEXCEPT            = default;
0086   _LIBCPP_HIDE_FROM_ABI bad_exception& operator=(const bad_exception&) _NOEXCEPT = default;
0087   ~bad_exception() _NOEXCEPT override;
0088   const char* what() const _NOEXCEPT override;
0089 };
0090 #endif // !_LIBCPP_ABI_VCRUNTIME
0091 
0092 } // namespace std
0093 
0094 #endif // _LIBCPP___CXX03___EXCEPTION_EXCEPTION_H