1 // RTTI support for -*- C++ -*-
2 // Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 // 2003, 2004, 2005, 2006, 2007
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 2, 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 // You should have received a copy of the GNU General Public License
19 // along with GCC; see the file COPYING. If not, write to
20 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301, USA.
23 // As a special exception, you may use this file as part of a free software
24 // library without restriction. Specifically, if other files instantiate
25 // templates or use macros or inline functions from this file, or you compile
26 // this file and link it with other files to produce an executable, this
27 // file does not by itself cause the resulting executable to be covered by
28 // the GNU General Public License. This exception does not however
29 // invalidate any other reasons why the executable file might be covered by
30 // the GNU General Public License.
33 * This is a Standard C++ Library header.
41 #pragma GCC visibility push(default)
47 class __class_type_info;
48 } // namespace __cxxabiv1
50 // Determine whether typeinfo names for the same type are merged (in which
51 // case comparison can just compare pointers) or not (in which case
52 // strings must be compared and g++.dg/abi/local1.C will fail), and
53 // whether comparison is to be implemented inline or not. By default we
54 // use inline pointer comparison if weak symbols are available, and
55 // out-of-line strcmp if not. Out-of-line pointer comparison is used
56 // where the object files are to be portable to multiple systems, some of
57 // which may not be able to use pointer comparison, but the particular
58 // system for which libstdc++ is being built can use pointer comparison;
59 // in particular for most ARM EABI systems, where the ABI specifies
60 // out-of-line comparison. Inline strcmp is not currently supported. The
61 // compiler's target configuration can override the defaults by defining
62 // __GXX_TYPEINFO_EQUALITY_INLINE to 1 or 0 to indicate whether or not
63 // comparison is inline, and __GXX_MERGED_TYPEINFO_NAMES to 1 or 0 to
64 // indicate whether or not pointer comparison can be used.
66 #ifndef __GXX_MERGED_TYPEINFO_NAMES
68 // If weak symbols are not supported, typeinfo names are not merged.
69 #define __GXX_MERGED_TYPEINFO_NAMES 0
71 // On platforms that support weak symbols, typeinfo names are merged.
72 #define __GXX_MERGED_TYPEINFO_NAMES 1
76 // By default follow the same rules as for __GXX_MERGED_TYPEINFO_NAMES.
77 #ifndef __GXX_TYPEINFO_EQUALITY_INLINE
79 #define __GXX_TYPEINFO_EQUALITY_INLINE 0
81 #define __GXX_TYPEINFO_EQUALITY_INLINE 1
88 * @brief Part of RTTI.
90 * The @c type_info class describes type information generated by
96 /** Destructor first. Being the first non-inline virtual function, this
97 * controls in which translation unit the vtable is emitted. The
98 * compiler makes use of that information to know where to emit
99 * the runtime-mandated type_info structures in the new-abi. */
100 virtual ~type_info();
102 /** Returns an @e implementation-defined byte string; this is not
103 * portable between compilers! */
104 const char* name() const
107 #if !__GXX_TYPEINFO_EQUALITY_INLINE
108 bool before(const type_info& __arg) const;
110 // In old abi, or when weak symbols are not supported, there can
111 // be multiple instances of a type_info object for one
112 // type. Uniqueness must use the _name value, not object address.
113 bool operator==(const type_info& __arg) const;
115 #if !__GXX_MERGED_TYPEINFO_NAMES
116 #error "Inline implementation of type_info comparision requires merging of type_info objects"
118 /** Returns true if @c *this precedes @c __arg in the implementation's
119 * collation order. */
120 // In new abi we can rely on type_info's NTBS being unique,
121 // and therefore address comparisons are sufficient.
122 bool before(const type_info& __arg) const
123 { return __name < __arg.__name; }
125 bool operator==(const type_info& __arg) const
126 { return __name == __arg.__name; }
128 bool operator!=(const type_info& __arg) const
129 { return !operator==(__arg); }
131 // Return true if this is a pointer type of some kind
132 virtual bool __is_pointer_p() const;
134 // Return true if this is a function type
135 virtual bool __is_function_p() const;
137 // Try and catch a thrown type. Store an adjusted pointer to the
138 // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then
139 // THR_OBJ points to the thrown object. If THR_TYPE is a pointer
140 // type, then THR_OBJ is the pointer itself. OUTER indicates the
141 // number of outer pointers, and whether they were const
143 virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj,
144 unsigned __outer) const;
146 // Internally used during catch matching
147 virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target,
148 void **__obj_ptr) const;
153 explicit type_info(const char *__n): __name(__n) { }
156 /// Assigning type_info is not supported.
157 type_info& operator=(const type_info&);
158 type_info(const type_info&);
162 * @brief Thrown during incorrect typecasting.
164 * If you attempt an invalid @c dynamic_cast expression, an instance of
165 * this class (or something derived from this class) is thrown. */
166 class bad_cast : public exception
169 bad_cast() throw() { }
171 // This declaration is not useless:
172 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
173 virtual ~bad_cast() throw();
175 // See comment in eh_exception.cc.
176 virtual const char* what() const throw();
179 /** If you use a NULL pointer in a @c typeid expression, this is thrown. */
180 class bad_typeid : public exception
183 bad_typeid () throw() { }
185 // This declaration is not useless:
186 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
187 virtual ~bad_typeid() throw();
189 // See comment in eh_exception.cc.
190 virtual const char* what() const throw();
194 #pragma GCC visibility pop