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
47 // strings must be compared and g++.dg/abi/local1.C will fail), and
48 // whether comparison is to be implemented inline or not. By default we
49 // use inline pointer comparison if weak symbols are available, and
50 // out-of-line strcmp if not. Out-of-line pointer comparison is used
51 // where the object files are to be portable to multiple systems, some of
52 // which may not be able to use pointer comparison, but the particular
53 // system for which libstdc++ is being built can use pointer comparison;
54 // in particular for most ARM EABI systems, where the ABI specifies
55 // out-of-line comparison. Inline strcmp is not currently supported. The
56 // compiler's target configuration can override the defaults by defining
57 // __GXX_TYPEINFO_EQUALITY_INLINE to 1 or 0 to indicate whether or not
58 // comparison is inline, and __GXX_MERGED_TYPEINFO_NAMES to 1 or 0 to
59 // indicate whether or not pointer comparison can be used.
61 #ifndef __GXX_MERGED_TYPEINFO_NAMES
63 // If weak symbols are not supported, typeinfo names are not merged.
64 #define __GXX_MERGED_TYPEINFO_NAMES 0
66 // On platforms that support weak symbols, typeinfo names are merged.
67 #define __GXX_MERGED_TYPEINFO_NAMES 1
71 // By default follow the same rules as for __GXX_MERGED_TYPEINFO_NAMES.
72 #ifndef __GXX_TYPEINFO_EQUALITY_INLINE
74 #define __GXX_TYPEINFO_EQUALITY_INLINE 0
76 #define __GXX_TYPEINFO_EQUALITY_INLINE 1
83 * @brief Part of RTTI.
85 * The @c type_info class describes type information generated by
91 /** Destructor first. Being the first non-inline virtual function, this
92 * controls in which translation unit the vtable is emitted. The
93 * compiler makes use of that information to know where to emit
94 * the runtime-mandated type_info structures in the new-abi. */
97 /** Returns an @e implementation-defined byte string; this is not
98 * portable between compilers! */
99 const char* name() const
102 #if !__GXX_TYPEINFO_EQUALITY_INLINE
103 bool before(const type_info& __arg) const;
105 // In old abi, or when weak symbols are not supported, there can
106 // be multiple instances of a type_info object for one
107 // type. Uniqueness must use the _name value, not object address.
108 bool operator==(const type_info& __arg) const;
110 #if !__GXX_MERGED_TYPEINFO_NAMES
111 #error "Inline implementation of type_info comparision requires merging of type_info objects"
113 /** Returns true if @c *this precedes @c __arg in the implementation's
114 * collation order. */
115 // In new abi we can rely on type_info's NTBS being unique,
116 // and therefore address comparisons are sufficient.
117 bool before(const type_info& __arg) const
118 { return __name < __arg.__name; }
120 bool operator==(const type_info& __arg) const
121 { return __name == __arg.__name; }
123 bool operator!=(const type_info& __arg) const
124 { return !operator==(__arg); }
126 // Return true if this is a pointer type of some kind
127 virtual bool __is_pointer_p() const;
129 // Return true if this is a function type
130 virtual bool __is_function_p() const;
132 // Try and catch a thrown type. Store an adjusted pointer to the
133 // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then
134 // THR_OBJ points to the thrown object. If THR_TYPE is a pointer
135 // type, then THR_OBJ is the pointer itself. OUTER indicates the
136 // number of outer pointers, and whether they were const
138 virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj,
139 unsigned __outer) const;
141 // Internally used during catch matching
142 virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target,
143 void **__obj_ptr) const;
148 explicit type_info(const char *__n): __name(__n) { }
151 /// Assigning type_info is not supported.
152 type_info& operator=(const type_info&);
153 type_info(const type_info&);
157 * @brief Thrown during incorrect typecasting.
158 * @ingroup exceptions
160 * If you attempt an invalid @c dynamic_cast expression, an instance of
161 * this class (or something derived from this class) is thrown. */
162 class bad_cast : public exception
165 bad_cast() throw() { }
167 // This declaration is not useless:
168 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
169 virtual ~bad_cast() throw();
171 // See comment in eh_exception.cc.
172 virtual const char* what() const throw();
176 * @brief Thrown when a NULL pointer in a @c typeid expression is used.
177 * @ingroup exceptions
179 class bad_typeid : public exception
182 bad_typeid () throw() { }
184 // This declaration is not useless:
185 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
186 virtual ~bad_typeid() throw();
188 // See comment in eh_exception.cc.
189 virtual const char* what() const throw();
193 #pragma GCC visibility pop