hokein created this revision. hokein added a reviewer: kadircet. Herald added a subscriber: kristof.beyls. Herald added a project: All. hokein requested review of this revision. Herald added a project: clang-tools-extra.
This will fix a false positive where a ParamVarDecl happend to be the same name of some C standard symbol and has a global namespace. using A = int(int time); // we suggest <ctime> for the `int time`. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D153330 Files: clang-tools-extra/include-cleaner/lib/WalkAST.cpp clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp =================================================================== --- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp +++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp @@ -91,12 +91,14 @@ #include "header.h" #include "private.h" - void $bar^bar($private^Private $p^p) { + void $bar^bar($private^Private p) { $foo^foo(); std::$vector^vector $vconstructor^$v^v; $builtin^__builtin_popcount(1); std::$move^move(3); } + // No reference reported for the Parameter. + using A = int(int time); )cpp"); Inputs.Code = Code.code(); Inputs.ExtraFiles["header.h"] = guard(R"cpp( @@ -120,7 +122,6 @@ offsetToProviders(AST, SM), UnorderedElementsAre( Pair(Code.point("bar"), UnorderedElementsAre(MainFile)), - Pair(Code.point("p"), UnorderedElementsAre(MainFile)), Pair(Code.point("private"), UnorderedElementsAre(PublicFile, PrivateFile)), Pair(Code.point("foo"), UnorderedElementsAre(HeaderFile)), 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 @@ -214,6 +214,10 @@ return true; } bool VisitVarDecl(VarDecl *VD) { + // Ignore the parameter decl itself (its children were handled elsewhere), + // as they don't contribute to the main-file #include. + if (isa<ParmVarDecl>(VD)) + return true; // Mark declaration from definition as it needs type-checking. if (VD->isThisDeclarationADefinition()) report(VD->getLocation(), VD);
Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp =================================================================== --- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp +++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp @@ -91,12 +91,14 @@ #include "header.h" #include "private.h" - void $bar^bar($private^Private $p^p) { + void $bar^bar($private^Private p) { $foo^foo(); std::$vector^vector $vconstructor^$v^v; $builtin^__builtin_popcount(1); std::$move^move(3); } + // No reference reported for the Parameter. + using A = int(int time); )cpp"); Inputs.Code = Code.code(); Inputs.ExtraFiles["header.h"] = guard(R"cpp( @@ -120,7 +122,6 @@ offsetToProviders(AST, SM), UnorderedElementsAre( Pair(Code.point("bar"), UnorderedElementsAre(MainFile)), - Pair(Code.point("p"), UnorderedElementsAre(MainFile)), Pair(Code.point("private"), UnorderedElementsAre(PublicFile, PrivateFile)), Pair(Code.point("foo"), UnorderedElementsAre(HeaderFile)), 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 @@ -214,6 +214,10 @@ return true; } bool VisitVarDecl(VarDecl *VD) { + // Ignore the parameter decl itself (its children were handled elsewhere), + // as they don't contribute to the main-file #include. + if (isa<ParmVarDecl>(VD)) + return true; // Mark declaration from definition as it needs type-checking. if (VD->isThisDeclarationADefinition()) report(VD->getLocation(), VD);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits