diff --git a/include/abg-fwd.h b/include/abg-fwd.h index 9b75876e..b0eea971 100644 --- a/include/abg-fwd.h +++ b/include/abg-fwd.h @@ -158,6 +158,12 @@ is_typedef(const shared_ptr); shared_ptr is_typedef(const shared_ptr); +shared_ptr +is_class_type(const shared_ptr); + +shared_ptr +is_class_type(const shared_ptr); + shared_ptr look_through_decl_only_class(shared_ptr); diff --git a/src/abg-comp-filter.cc b/src/abg-comp-filter.cc index 8cce8f20..6fa572e8 100644 --- a/src/abg-comp-filter.cc +++ b/src/abg-comp-filter.cc @@ -233,8 +233,8 @@ harmful_filter::visit(diff* d, bool pre) if (type_size_changed(f, s) || data_member_offset_changed(f, s)) { - class_decl_sptr cl1 = dynamic_pointer_cast(f), - cl2 = dynamic_pointer_cast(s); + class_decl_sptr cl1 = is_class_type(f), + cl2 = is_class_type(s); if ((cl1 && cl1->get_is_declaration_only()) || (cl2 && cl2->get_is_declaration_only())) // But do not compare a declaration-only class to another diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 68c3dbcf..82b8bd57 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -1648,6 +1648,33 @@ typedef_decl_sptr is_typedef(const decl_base_sptr d) {return is_typedef(is_type(d));} +/// Test whether a type is a class. +/// +/// This function looks through typedefs. +/// +/// @parm t the type to consider. +/// +/// @return the class_decl if @p t is a class_decl or null otherwise. +class_decl_sptr +is_class_type(const type_base_sptr t) +{ + if (!t) + return class_decl_sptr(); + type_base_sptr ty = strip_typedef(t); + return dynamic_pointer_cast(ty); +} + +/// Test whether a type is a class. +/// +/// This function looks through typedefs. +/// +/// @parm d the declaration of the type to consider. +/// +/// @return the class_decl if @p d is a class_decl or null otherwise. +class_decl_sptr +is_class_type(const decl_base_sptr d) +{return is_class_type(is_type(d));} + /// If a class is a decl-only class, get its definition. Otherwise, /// just return the initial class. ///