VitaNuo created this revision. Herald added a subscriber: kadircet. Herald added a project: All. VitaNuo requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D139087 Files: clang-tools-extra/include-cleaner/lib/WalkAST.cpp clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp =================================================================== --- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp @@ -172,10 +172,12 @@ } TEST(WalkAST, MemberExprs) { - testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); }"); + testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); }"); testWalk( - "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };", + "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };", "void foo() { X{}.^foo(); }"); + testWalk("struct Base { int a; }; struct $explicit^Derived : public Base {};", + "void fun(Derived d) { d.^a; }"); } TEST(WalkAST, ConstructExprs) { Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -59,7 +59,11 @@ } bool VisitMemberExpr(MemberExpr *E) { - report(E->getMemberLoc(), E->getFoundDecl().getDecl()); + // Instead of the FieldDecl for MemberExpr, we report the Decl of + // the corresponding record. + Expr *BE = E->getBase()->IgnoreImpCasts(); + RecordDecl *RD = BE->getType()->getAsRecordDecl(); + report(E->getMemberLoc(), RD); return true; }
Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp =================================================================== --- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp @@ -172,10 +172,12 @@ } TEST(WalkAST, MemberExprs) { - testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); }"); + testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); }"); testWalk( - "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };", + "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };", "void foo() { X{}.^foo(); }"); + testWalk("struct Base { int a; }; struct $explicit^Derived : public Base {};", + "void fun(Derived d) { d.^a; }"); } TEST(WalkAST, ConstructExprs) { Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -59,7 +59,11 @@ } bool VisitMemberExpr(MemberExpr *E) { - report(E->getMemberLoc(), E->getFoundDecl().getDecl()); + // Instead of the FieldDecl for MemberExpr, we report the Decl of + // the corresponding record. + Expr *BE = E->getBase()->IgnoreImpCasts(); + RecordDecl *RD = BE->getType()->getAsRecordDecl(); + report(E->getMemberLoc(), RD); return true; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits