Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -245,6 +245,7 @@ - Added ``__builtin_elementwise_nearbyint`` for floating point types. This allows access to ``llvm.nearbyint`` for arbitrary floating-point and vector of floating-point types. +- Clang AST matcher now matches concept declarations. New Compiler Flags ------------------ Index: clang/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- clang/include/clang/ASTMatchers/ASTMatchers.h +++ clang/include/clang/ASTMatchers/ASTMatchers.h @@ -1334,6 +1334,16 @@ extern const internal::VariadicDynCastAllOfMatcher cxxDeductionGuideDecl; +/// Matches concept declarations. +/// +/// Example matches a +/// \code +/// template +/// concept integral = std::is_integral_v; +/// \endcode +extern const internal::VariadicDynCastAllOfMatcher + conceptDecl; + /// Matches variable declarations. /// /// Note: this does not match declarations of member variables, which are Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp =================================================================== --- clang/lib/ASTMatchers/ASTMatchersInternal.cpp +++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -800,6 +800,7 @@ const internal::VariadicDynCastAllOfMatcher cxxMethodDecl; const internal::VariadicDynCastAllOfMatcher cxxConversionDecl; +const internal::VariadicDynCastAllOfMatcher conceptDecl; const internal::VariadicDynCastAllOfMatcher varDecl; const internal::VariadicDynCastAllOfMatcher fieldDecl; const internal::VariadicDynCastAllOfMatcher Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -170,6 +170,7 @@ REGISTER_MATCHER(compoundLiteralExpr); REGISTER_MATCHER(compoundStmt); REGISTER_MATCHER(coawaitExpr); + REGISTER_MATCHER(conceptDecl); REGISTER_MATCHER(conditionalOperator); REGISTER_MATCHER(constantArrayType); REGISTER_MATCHER(constantExpr); Index: clang/unittests/AST/DeclTest.cpp =================================================================== --- clang/unittests/AST/DeclTest.cpp +++ clang/unittests/AST/DeclTest.cpp @@ -12,9 +12,11 @@ #include "clang/AST/Decl.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/DeclTemplate.h" #include "clang/AST/Mangle.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/TargetInfo.h" #include "clang/Lex/Lexer.h" @@ -140,6 +142,22 @@ ASSERT_TRUE(0 == MangleB.compare("_ZTSAT0__T_")); } +TEST(Decl, ConceptDecl) { + llvm::StringRef Code(R"( + template + concept integral = __is_integral(T); + )"); + + auto AST = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++20"}); + ASTContext &Ctx = AST->getASTContext(); + SourceManager &SM = Ctx.getSourceManager(); + + const auto *Decl = + selectFirst("decl", match(conceptDecl().bind("decl"), Ctx)); + ASSERT_TRUE(Decl != nullptr); + EXPECT_EQ(Decl->getName(), "integral"); +} + TEST(Decl, EnumDeclRange) { llvm::Annotations Code(R"( typedef int Foo;