Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -4607,6 +4607,12 @@ +Matcher<ReturnStmt>hasRetValueMatcher<Expr> InnerMatcher +
Matches the return expression of a return statement.
+
+
+ + Matcher<Stmt>alignOfExprMatcher<UnaryExprOrTypeTraitExpr> InnerMatcher
Same as unaryExprOrTypeTraitExpr, but only matching
 alignof.
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2977,6 +2977,14 @@
   return InnerMatcher.matches(Node.getReturnType(), Finder, Builder);
 }
 
+/// \brief Matches the return expression of a return statement.
+///
+AST_MATCHER_P(ReturnStmt, hasRetValue, internal::Matcher, InnerMatcher) {
+  const Expr *const RetValue = Node.getRetValue();
+  return RetValue != nullptr &&
+         InnerMatcher.matches(*RetValue, Finder, Builder);
+}
+
 /// \brief Matches extern "C" function declarations.
 ///
 /// Given:
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -235,6 +235,7 @@
   REGISTER_MATCHER(hasQualifier);
   REGISTER_MATCHER(hasRangeInit);
   REGISTER_MATCHER(hasReceiverType);
+  REGISTER_MATCHER(hasRetValue);
   REGISTER_MATCHER(hasRHS);
   REGISTER_MATCHER(hasSelector);
   REGISTER_MATCHER(hasSingleDecl);
Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -1807,6 +1807,11 @@
                           recordDecl(hasName("Y")))))));
 }
 
+TEST(HasRetValue, MatchesReturnExpressions) {
+  EXPECT_TRUE(
+      matches("bool f() { return true; }", returnStmt(hasRetValue(expr()))));
+}
+
 TEST(IsExternC, MatchesExternCFunctionDeclarations) {
   EXPECT_TRUE(matches("extern \"C\" void f() {}", functionDecl(isExternC())));
   EXPECT_TRUE(matches("extern \"C\" { void f() {} }",