Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h @@ -5013,9 +5013,11 @@ /// matches 'return a + b' /// with binaryOperator() /// matching 'a + b' -AST_MATCHER_P(ReturnStmt, hasReturnValue, internal::Matcher, +AST_MATCHER_P(ReturnStmt, hasReturnValue, internal::Matcher, InnerMatcher) { - return InnerMatcher.matches(*Node.getRetValue(), Finder, Builder); + if (const auto *RetValue = Node.getRetValue()) + return InnerMatcher.matches(*RetValue, Finder, Builder); + return false; } Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp =================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp +++ cfe/trunk/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