diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index e010133ca238..167b0fc7906b 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -555,7 +555,7 @@ const internal::VariadicDynCastAllOfMatcher< /// /// Example matches y /// \code -/// class X { void y() }; +/// class X { void y(); }; /// \endcode const internal::VariadicDynCastAllOfMatcher methodDecl; @@ -2656,6 +2656,20 @@ AST_MATCHER(CXXMethodDecl, isVirtual) { return Node.isVirtual(); } +/// \brief Matches if the given method declaration is pure. +/// +/// Given +/// \code +/// class A { +/// public: +/// virtual void x() = 0; +/// }; +/// \endcode +/// matches A::x +AST_MATCHER(CXXMethodDecl, isPure) { + return Node.isPure(); +} + /// \brief Matches if the given method declaration is const. /// /// Given diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index cf77f2f4dd57..aa3c795b57d0 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1588,6 +1588,13 @@ TEST(Matcher, MatchesVirtualMethod) { methodDecl(isVirtual()))); } +TEST(Matcher, MatchesPureMethod) { + EXPECT_TRUE(matches("class X { virtual int f() = 0; };", + methodDecl(isPure(), hasName("::X::f")))); + EXPECT_TRUE(notMatches("class X { int f(); };", + methodDecl(isPure()))); +} + TEST(Matcher, MatchesConstMethod) { EXPECT_TRUE(matches("struct A { void foo() const; };", methodDecl(isConst())));