summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h6
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTest.cpp1
2 files changed, 5 insertions, 2 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 04d6938a2d9..9a89cd1e381 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -5013,9 +5013,11 @@ AST_MATCHER_P(Decl, hasAttr, attr::Kind, AttrKind) {
/// matches 'return a + b'
/// with binaryOperator()
/// matching 'a + b'
-AST_MATCHER_P(ReturnStmt, hasReturnValue, internal::Matcher<Expr>,
+AST_MATCHER_P(ReturnStmt, hasReturnValue, internal::Matcher<Expr>,
InnerMatcher) {
- return InnerMatcher.matches(*Node.getRetValue(), Finder, Builder);
+ if (const auto *RetValue = Node.getRetValue())
+ return InnerMatcher.matches(*RetValue, Finder, Builder);
+ return false;
}
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index a3461793579..e4b6bb17033 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -5500,6 +5500,7 @@ TEST(StatementMatcher, HasReturnValue) {
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
OpenPOWER on IntegriCloud