Author: Utkarsh Saxena Date: 2023-08-31T13:57:22+02:00 New Revision: ac2d2652db8de9ea2b750dd2bf1232941039dffe
URL: https://github.com/llvm/llvm-project/commit/ac2d2652db8de9ea2b750dd2bf1232941039dffe DIFF: https://github.com/llvm/llvm-project/commit/ac2d2652db8de9ea2b750dd2bf1232941039dffe.diff LOG: [include-cleaner] Handle decls/refs to concepts Added: Modified: clang-tools-extra/include-cleaner/lib/WalkAST.cpp clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp index e3ba2d3b604072..15a579afd456c3 100644 --- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -241,6 +241,11 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> { return true; } + bool VisitConceptReference(const ConceptReference *CR) { + report(CR->getConceptNameLoc(), CR->getFoundDecl()); + return true; + } + // Report a reference from explicit specializations to the specialized // template. Implicit ones are filtered out by RAV and explicit instantiations // are already traversed through typelocs. diff --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp index 67248d4eedb915..f53959877dc513 100644 --- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp @@ -528,5 +528,16 @@ TEST(WalkAST, InitializerList) { const char* s = ""; auto sx = ^{s};)cpp"); } + +TEST(WalkAST, Concepts) { + std::string Concept = "template<typename T> concept $explicit^Foo = true;"; + testWalk(Concept, "template<typename T>concept Bar = ^Foo<T> && true;"); + testWalk(Concept, "template<^Foo T>void func() {}"); + testWalk(Concept, "template<typename T> requires ^Foo<T> void func() {}"); + testWalk(Concept, "template<typename T> void func() requires ^Foo<T> {}"); + testWalk(Concept, "void func(^Foo auto x) {}"); + // FIXME: Foo should be explicitly referenced. + testWalk("template<typename T> concept Foo = true;", "void func() { ^Foo auto x = 1; }"); +} } // namespace } // namespace clang::include_cleaner _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
