From 3790613579db81a9f78a7ddad5382dbeec43a07a Mon Sep 17 00:00:00 2001
From: Dmitri Gribenko <gribozavr@gmail.com>
Date: Mon, 24 Feb 2014 09:27:46 +0000
Subject: [PATCH] ASTMatchers: added CXXMethodDecl matcher isPure()

The isPure() CXXMethodDecl matcher matches pure method declaration like "A::x"
in this example:

class A {
  virtual void x() = 0;
}

Patch by Konrad Kleine.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202012 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/clang/ASTMatchers/ASTMatchers.h   | 16 +++++++++++++++-
 unittests/ASTMatchers/ASTMatchersTest.cpp |  7 +++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h
index e010133ca23..167b0fc7906 100644
--- a/include/clang/ASTMatchers/ASTMatchers.h
+++ b/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<Decl, CXXMethodDecl> 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/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index cf77f2f4dd5..aa3c795b57d 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/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())));
-- 
GitLab