Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -1845,6 +1845,20 @@ matches A::x +
Matches if the given method declaration has an explicit "virtual". + +Given + class A { + public: + virtual void x(); + }; + class B : public A { + public: + void x(); + }; + matches A::x but not B::x +
Matches overloaded operator names. Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -3479,6 +3479,24 @@ return Node.isVirtual(); } +/// \brief Matches if the given method declaration has an explicit "virtual". +/// +/// Given +/// \code +/// class A { +/// public: +/// virtual void x(); +/// }; +/// class B : public A { +/// public: +/// void x(); +/// }; +/// \endcode +/// matches A::x but not B::x +AST_MATCHER(CXXMethodDecl, isVirtualAsWritten) { + return Node.isVirtualAsWritten(); +} + /// \brief Matches if the given method or class declaration is final. /// /// Given: Index: lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -302,6 +302,7 @@ REGISTER_MATCHER(isUnion); REGISTER_MATCHER(isVariadic); REGISTER_MATCHER(isVirtual); + REGISTER_MATCHER(isVirtualAsWritten); REGISTER_MATCHER(isVolatileQualified); REGISTER_MATCHER(isWritten); REGISTER_MATCHER(labelStmt); Index: unittests/ASTMatchers/ASTMatchersTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersTest.cpp +++ unittests/ASTMatchers/ASTMatchersTest.cpp @@ -2028,6 +2028,16 @@ EXPECT_TRUE(notMatches("class X { int f(); };", cxxMethodDecl(isVirtual()))); } +TEST(Matcher, MatchesVirtualAsWrittenMethod) { + EXPECT_TRUE(matches("class A { virtual int f(); };" + "class B : public A { int f(); };", + cxxMethodDecl(isVirtualAsWritten(), hasName("::A::f")))); + EXPECT_TRUE( + notMatches("class A { virtual int f(); };" + "class B : public A { int f(); };", + cxxMethodDecl(isVirtualAsWritten(), hasName("::B::f")))); +} + TEST(Matcher, MatchesPureMethod) { EXPECT_TRUE(matches("class X { virtual int f() = 0; };", cxxMethodDecl(isPure(), hasName("::X::f"))));