1 // RTTI support for -*- C++ -*-
2 // Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 // 2003, 2004, 2005, 2006, 2007, 2009
4 // Free Software Foundation
6 // This file is part of GCC.
8 // GCC is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3, or (at your option)
13 // GCC is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // Under Section 7 of GPL version 3, you are granted additional
19 // permissions described in the GCC Runtime Library Exception, version
20 // 3.1, as published by the Free Software Foundation.
22 // You should have received a copy of the GNU General Public License and
23 // a copy of the GCC Runtime Library Exception along with this program;
24 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 // <http://www.gnu.org/licenses/>.
28 * This is a Standard C++ Library header.
36 #pragma GCC visibility push(default)
42 class __class_type_info;
43 } // namespace __cxxabiv1
45 // Determine whether typeinfo names for the same type are merged (in which
46 // case comparison can just compare pointers) or not (in which case strings
47 // must be compared), and whether comparison is to be implemented inline or
48 // not. We used to do inline pointer comparison by default if weak symbols
49 // are available, but even with weak symbols sometimes names are not merged
50 // when objects are loaded with RTLD_LOCAL, so now we always use strcmp by
51 // default. For ABI compatibility, we do the strcmp inline if weak symbols
52 // are available, and out-of-line if not. Out-of-line pointer comparison
53 // is used where the object files are to be portable to multiple systems,
54 // some of which may not be able to use pointer comparison, but the
55 // particular system for which libstdc++ is being built can use pointer
56 // comparison; in particular for most ARM EABI systems, where the ABI
57 // specifies out-of-line comparison. The compiler's target configuration
58 // can override the defaults by defining __GXX_TYPEINFO_EQUALITY_INLINE to
59 // 1 or 0 to indicate whether or not comparison is inline, and
60 // __GXX_MERGED_TYPEINFO_NAMES to 1 or 0 to indicate whether or not pointer
61 // comparison can be used.
63 #ifndef __GXX_MERGED_TYPEINFO_NAMES
64 // By default, typeinfo names are not merged.
65 #define __GXX_MERGED_TYPEINFO_NAMES 0
68 // By default follow the old inline rules to avoid ABI changes.
69 #ifndef __GXX_TYPEINFO_EQUALITY_INLINE
71 #define __GXX_TYPEINFO_EQUALITY_INLINE 0
73 #define __GXX_TYPEINFO_EQUALITY_INLINE 1
80 * @brief Part of RTTI.
82 * The @c type_info class describes type information generated by
88 /** Destructor first. Being the first non-inline virtual function, this
89 * controls in which translation unit the vtable is emitted. The
90 * compiler makes use of that information to know where to emit
91 * the runtime-mandated type_info structures in the new-abi. */
94 /** Returns an @e implementation-defined byte string; this is not
95 * portable between compilers! */
96 const char* name() const
99 #if !__GXX_TYPEINFO_EQUALITY_INLINE
100 // In old abi, or when weak symbols are not supported, there can
101 // be multiple instances of a type_info object for one
102 // type. Uniqueness must use the _name value, not object address.
103 bool before(const type_info& __arg) const;
104 bool operator==(const type_info& __arg) const;
106 #if !__GXX_MERGED_TYPEINFO_NAMES
107 /** Returns true if @c *this precedes @c __arg in the implementation's
108 * collation order. */
109 // Even with the new abi, on systems that support dlopen
110 // we can run into cases where type_info names aren't merged,
111 // so we still need to do string comparison.
112 bool before(const type_info& __arg) const
113 { return __builtin_strcmp (__name, __arg.__name) < 0; }
115 bool operator==(const type_info& __arg) const
117 return ((__name == __arg.__name)
118 || __builtin_strcmp (__name, __arg.__name) == 0);
121 // On some targets we can rely on type_info's NTBS being unique,
122 // and therefore address comparisons are sufficient.
123 bool before(const type_info& __arg) const
124 { return __name < __arg.__name; }
126 bool operator==(const type_info& __arg) const
127 { return __name == __arg.__name; }
130 bool operator!=(const type_info& __arg) const
131 { return !operator==(__arg); }
133 // Return true if this is a pointer type of some kind
134 virtual bool __is_pointer_p() const;
136 // Return true if this is a function type
137 virtual bool __is_function_p() const;
139 // Try and catch a thrown type. Store an adjusted pointer to the
140 // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then
141 // THR_OBJ points to the thrown object. If THR_TYPE is a pointer
142 // type, then THR_OBJ is the pointer itself. OUTER indicates the
143 // number of outer pointers, and whether they were const
145 virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj,
146 unsigned __outer) const;
148 // Internally used during catch matching
149 virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target,
150 void **__obj_ptr) const;
155 explicit type_info(const char *__n): __name(__n) { }
158 /// Assigning type_info is not supported.
159 type_info& operator=(const type_info&);
160 type_info(const type_info&);
164 * @brief Thrown during incorrect typecasting.
165 * @ingroup exceptions
167 * If you attempt an invalid @c dynamic_cast expression, an instance of
168 * this class (or something derived from this class) is thrown. */
169 class bad_cast : public exception
172 bad_cast() throw() { }
174 // This declaration is not useless:
175 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
176 virtual ~bad_cast() throw();
178 // See comment in eh_exception.cc.
179 virtual const char* what() const throw();
183 * @brief Thrown when a NULL pointer in a @c typeid expression is used.
184 * @ingroup exceptions
186 class bad_typeid : public exception
189 bad_typeid () throw() { }
191 // This declaration is not useless:
192 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
193 virtual ~bad_typeid() throw();
195 // See comment in eh_exception.cc.
196 virtual const char* what() const throw();
200 #pragma GCC visibility pop