diff --git a/iwyu.cc b/iwyu.cc index 7b3e0b8be..ef2248dc9 100644 --- a/iwyu.cc +++ b/iwyu.cc @@ -609,9 +609,8 @@ class BaseAstVisitor : public RecursiveASTVisitor { member_types.insert(it->getType().getTypePtr()); } for (const Type* type : member_types) { - const NamedDecl* member_decl = TypeToDeclAsWritten(type); // We only want those fields that are c++ classes. - if (const CXXRecordDecl* cxx_field_decl = DynCastFrom(member_decl)) { + if (const CXXRecordDecl* cxx_field_decl = type->getAsCXXRecordDecl()) { if (const CXXDestructorDecl* field_dtor = cxx_field_decl->getDestructor()) { if (!this->getDerived().TraverseImplicitDestructorCall( diff --git a/tests/cxx/template_member_functions.cc b/tests/cxx/template_member_functions.cc index 2541b38ae..bec75c4db 100644 --- a/tests/cxx/template_member_functions.cc +++ b/tests/cxx/template_member_functions.cc @@ -18,11 +18,22 @@ struct Tpl { static void StaticFn() { T t; } + + ~Tpl() { + T t; + } }; class IndirectClass; using NonProviding = Tpl; +struct Struct { + // IWYU: IndirectClass is...*indirect.h + ~Struct() = default; + + NonProviding member; +}; + void Fn() { // IWYU: IndirectClass is...*indirect.h NonProviding::StaticFn();