2 //===-------------------------- typeinfo ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef __LIBCPP_TYPEINFO
12 #define __LIBCPP_TYPEINFO
25 bool operator==(const type_info& rhs) const noexcept;
26 bool operator!=(const type_info& rhs) const noexcept;
28 bool before(const type_info& rhs) const noexcept;
29 size_t hash_code() const noexcept;
30 const char* name() const noexcept;
32 type_info(const type_info& rhs) = delete;
33 type_info& operator=(const type_info& rhs) = delete;
41 bad_cast(const bad_cast&) noexcept;
42 bad_cast& operator=(const bad_cast&) noexcept;
43 virtual const char* what() const noexcept;
50 bad_typeid() noexcept;
51 bad_typeid(const bad_typeid&) noexcept;
52 bad_typeid& operator=(const bad_typeid&) noexcept;
53 virtual const char* what() const noexcept;
64 #ifdef _LIBCPP_NO_EXCEPTIONS
68 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
69 #pragma GCC system_header
72 #if defined(_LIBCPP_NONUNIQUE_RTTI_BIT)
73 #define _LIBCPP_HAS_NONUNIQUE_TYPEINFO
75 #define _LIBCPP_HAS_UNIQUE_TYPEINFO
78 namespace std // purposefully not using versioning namespace
81 class _LIBCPP_EXCEPTION_ABI type_info
83 type_info& operator=(const type_info&);
84 type_info(const type_info&);
86 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
87 _LIBCPP_INLINE_VISIBILITY
88 int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT
89 { return __builtin_strcmp(name(), __arg.name()); }
93 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
94 // A const char* with the non-unique RTTI bit possibly set.
95 uintptr_t __type_name;
97 _LIBCPP_INLINE_VISIBILITY
98 type_info(const char* __n) : __type_name(reinterpret_cast<uintptr_t>(__n)) {}
100 const char *__type_name;
102 _LIBCPP_INLINE_VISIBILITY
103 type_info(const char* __n) : __type_name(__n) {}
107 virtual ~type_info();
109 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
110 _LIBCPP_INLINE_VISIBILITY
111 const char* name() const _NOEXCEPT
113 return reinterpret_cast<const char*>(__type_name &
114 ~_LIBCPP_NONUNIQUE_RTTI_BIT);
117 _LIBCPP_INLINE_VISIBILITY
118 bool before(const type_info& __arg) const _NOEXCEPT
120 if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
121 return __type_name < __arg.__type_name;
122 return __compare_nonunique_names(__arg) < 0;
125 _LIBCPP_INLINE_VISIBILITY
126 size_t hash_code() const _NOEXCEPT
128 if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT))
131 const char* __ptr = name();
132 size_t __hash = 5381;
133 while (unsigned char __c = static_cast<unsigned char>(*__ptr++))
134 __hash = (__hash * 33) ^ __c;
138 _LIBCPP_INLINE_VISIBILITY
139 bool operator==(const type_info& __arg) const _NOEXCEPT
141 if (__type_name == __arg.__type_name)
144 if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
146 return __compare_nonunique_names(__arg) == 0;
149 _LIBCPP_INLINE_VISIBILITY
150 const char* name() const _NOEXCEPT
151 { return __type_name; }
153 _LIBCPP_INLINE_VISIBILITY
154 bool before(const type_info& __arg) const _NOEXCEPT
155 { return __type_name < __arg.__type_name; }
157 _LIBCPP_INLINE_VISIBILITY
158 size_t hash_code() const _NOEXCEPT
159 { return reinterpret_cast<size_t>(__type_name); }
161 _LIBCPP_INLINE_VISIBILITY
162 bool operator==(const type_info& __arg) const _NOEXCEPT
163 { return __type_name == __arg.__type_name; }
166 _LIBCPP_INLINE_VISIBILITY
167 bool operator!=(const type_info& __arg) const _NOEXCEPT
168 { return !operator==(__arg); }
171 class _LIBCPP_EXCEPTION_ABI bad_cast
175 bad_cast() _NOEXCEPT;
176 virtual ~bad_cast() _NOEXCEPT;
177 virtual const char* what() const _NOEXCEPT;
180 class _LIBCPP_EXCEPTION_ABI bad_typeid
184 bad_typeid() _NOEXCEPT;
185 virtual ~bad_typeid() _NOEXCEPT;
186 virtual const char* what() const _NOEXCEPT;
191 _LIBCPP_BEGIN_NAMESPACE_STD
192 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
193 void __throw_bad_cast()
195 #ifndef _LIBCPP_NO_EXCEPTIONS
201 _LIBCPP_END_NAMESPACE_STD
203 #endif // __LIBCPP_TYPEINFO