Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -3128,7 +3128,8 @@ AST_POLYMORPHIC_MATCHER_P(hasBody, AST_POLYMORPHIC_SUPPORTED_TYPES(DoStmt, ForStmt, WhileStmt, - CXXForRangeStmt), + CXXForRangeStmt, + FunctionDecl), internal::Matcher, InnerMatcher) { const Stmt *const Statement = Node.getBody(); return (Statement != nullptr && Index: unittests/ASTMatchers/ASTMatchersTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersTest.cpp +++ unittests/ASTMatchers/ASTMatchersTest.cpp @@ -2869,6 +2869,10 @@ doStmt(hasBody(compoundStmt())))); EXPECT_TRUE(matches("void f() { int p[2]; for (auto x : p) {} }", cxxForRangeStmt(hasBody(compoundStmt())))); + EXPECT_TRUE(matches("void f() {}", functionDecl(hasBody(compoundStmt())))); + EXPECT_TRUE(notMatches("void f();", functionDecl(hasBody(compoundStmt())))); + EXPECT_TRUE(matches("void f(); void f() {}", + functionDecl(hasBody(compoundStmt())))); } TEST(HasAnySubstatement, MatchesForTopLevelCompoundStatement) { Index: unittests/ASTMatchers/Dynamic/ParserTest.cpp =================================================================== --- unittests/ASTMatchers/Dynamic/ParserTest.cpp +++ unittests/ASTMatchers/Dynamic/ParserTest.cpp @@ -263,7 +263,7 @@ "1:1: Matcher does not support binding.", ParseWithError("isArrow().bind(\"foo\")")); EXPECT_EQ("Input value has unresolved overloaded type: " - "Matcher", + "Matcher", ParseMatcherWithError("hasBody(stmt())")); }