[PATCH] D139087: [include-cleaner] Handle base class member access from derived class.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 1 04:18:52 PST 2022
hokein added inline comments.
================
Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:65
+ Expr *BE = E->getBase()->IgnoreImpCasts();
+ RecordDecl *RD = BE->getType()->getAsRecordDecl();
+ report(E->getMemberLoc(), RD);
----------------
This is not safe, we can get a nullptr if this type is not a normal `RecordType`.
I think there are more cases we need to handle:
1) pointer type (`Derived *`)
2) reference type (`Derived &`)
3) a dependent type
For the 3), some code like `std::vector<T>().size()`, it is tricky -- because we can't get any decl from a dependent type, we need some heuristics (in clangd we have some bits), we don't need to do that in this patch.
In the code implementation, we should add a dedicated `handleType(QualType)` helper to handle all these cases, so `VisitMemberExpr`, `VisitCXXDependentScopeMemberExpr` callbacks can just dispatch the type to this helper.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139087/new/
https://reviews.llvm.org/D139087
More information about the cfe-commits
mailing list