Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -5015,6 +5015,8 @@ /// matching 'a + b' AST_MATCHER_P(ReturnStmt, hasReturnValue, internal::Matcher, InnerMatcher) { + if (!Node.getRetValue()) + return false; return InnerMatcher.matches(*Node.getRetValue(), Finder, Builder); } Index: unittests/ASTMatchers/ASTMatchersTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersTest.cpp +++ unittests/ASTMatchers/ASTMatchersTest.cpp @@ -5500,6 +5500,7 @@ StatementMatcher RetVal = returnStmt(hasReturnValue(binaryOperator())); EXPECT_TRUE(matches("int F() { int a, b; return a + b; }", RetVal)); EXPECT_FALSE(matches("int F() { int a; return a; }", RetVal)); + EXPECT_FALSE(matches("void F() { return; }", RetVal)); } } // end namespace ast_matchers