tinfo.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Methods for type_info for -*- C++ -*- Run Time Type Identification.
  2. // Copyright (C) 1994-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of GCC.
  5. //
  6. // GCC is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation; either version 3, or (at your option)
  9. // any later version.
  10. // GCC is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. // Under Section 7 of GPL version 3, you are granted additional
  15. // permissions described in the GCC Runtime Library Exception, version
  16. // 3.1, as published by the Free Software Foundation.
  17. // You should have received a copy of the GNU General Public License and
  18. // a copy of the GCC Runtime Library Exception along with this program;
  19. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  20. // <http://www.gnu.org/licenses/>.
  21. #include <bits/c++config.h>
  22. #include <cstddef>
  23. #include "tinfo.h"
  24. std::type_info::
  25. ~type_info ()
  26. { }
  27. #if !__GXX_TYPEINFO_EQUALITY_INLINE
  28. #if __cplusplus > 202002L
  29. # error "this file must be compiled with C++20 or older to define operator=="
  30. #endif
  31. // We can't rely on common symbols being shared between shared objects.
  32. bool std::type_info::
  33. operator== (const std::type_info& arg) const _GLIBCXX_NOEXCEPT
  34. {
  35. #if __GXX_MERGED_TYPEINFO_NAMES
  36. return name () == arg.name ();
  37. #else
  38. /* The name() method will strip any leading '*' prefix. Therefore
  39. take care to look at __name rather than name() when looking for
  40. the "pointer" prefix. */
  41. return (&arg == this)
  42. || (__name[0] != '*' && (__builtin_strcmp (name (), arg.name ()) == 0));
  43. #endif
  44. }
  45. bool
  46. std::type_info::__equal (const std::type_info& arg) const _GLIBCXX_NOEXCEPT
  47. __attribute__((alias("_ZNKSt9type_infoeqERKS_")));
  48. #endif
  49. namespace std {
  50. // return true if this is a type_info for a pointer type
  51. bool type_info::
  52. __is_pointer_p () const
  53. {
  54. return false;
  55. }
  56. // return true if this is a type_info for a function type
  57. bool type_info::
  58. __is_function_p () const
  59. {
  60. return false;
  61. }
  62. // try and catch a thrown object.
  63. bool type_info::
  64. __do_catch (const type_info *thr_type, void **, unsigned) const
  65. {
  66. return *this == *thr_type;
  67. }
  68. // upcast from this type to the target. __class_type_info will override
  69. bool type_info::
  70. __do_upcast (const abi::__class_type_info *, void **) const
  71. {
  72. return false;
  73. }
  74. }