Skip to content

Commit

Permalink
Scan destructors of aliased type class members
Browse files Browse the repository at this point in the history
TypeToDeclAsWritten returns TypedefNameDecl in that case instead of
the original CXXRecordDecl. But Type::getAsCXXRecordDecl does the right
thing.

Found while investigating include-what-you-use#1499. The type of the _Hashtable member
of std::unordered_map is a typedef at least in the libstdc++
implementation.
  • Loading branch information
bolshakov-a committed Aug 5, 2024
1 parent b7cbe76 commit 4af435f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions iwyu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,8 @@ class BaseAstVisitor : public RecursiveASTVisitor<Derived> {
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(
Expand Down
11 changes: 11 additions & 0 deletions tests/cxx/template_member_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ struct Tpl {
static void StaticFn() {
T t;
}

~Tpl() {
T t;
}
};

class IndirectClass;
using NonProviding = Tpl<IndirectClass>;

struct Struct {
// IWYU: IndirectClass is...*indirect.h
~Struct() = default;

NonProviding member;
};

void Fn() {
// IWYU: IndirectClass is...*indirect.h
NonProviding::StaticFn();
Expand Down

0 comments on commit 4af435f

Please sign in to comment.