Skip to content

Commit ac2d265

Browse files
committed
[include-cleaner] Handle decls/refs to concepts
1 parent c39dcd2 commit ac2d265

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
241241
return true;
242242
}
243243

244+
bool VisitConceptReference(const ConceptReference *CR) {
245+
report(CR->getConceptNameLoc(), CR->getFoundDecl());
246+
return true;
247+
}
248+
244249
// Report a reference from explicit specializations to the specialized
245250
// template. Implicit ones are filtered out by RAV and explicit instantiations
246251
// are already traversed through typelocs.

clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,5 +528,16 @@ TEST(WalkAST, InitializerList) {
528528
const char* s = "";
529529
auto sx = ^{s};)cpp");
530530
}
531+
532+
TEST(WalkAST, Concepts) {
533+
std::string Concept = "template<typename T> concept $explicit^Foo = true;";
534+
testWalk(Concept, "template<typename T>concept Bar = ^Foo<T> && true;");
535+
testWalk(Concept, "template<^Foo T>void func() {}");
536+
testWalk(Concept, "template<typename T> requires ^Foo<T> void func() {}");
537+
testWalk(Concept, "template<typename T> void func() requires ^Foo<T> {}");
538+
testWalk(Concept, "void func(^Foo auto x) {}");
539+
// FIXME: Foo should be explicitly referenced.
540+
testWalk("template<typename T> concept Foo = true;", "void func() { ^Foo auto x = 1; }");
541+
}
531542
} // namespace
532543
} // namespace clang::include_cleaner

0 commit comments

Comments
 (0)