summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/docs/LibASTMatchersReference.html9
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h13
-rw-r--r--clang/lib/ASTMatchers/Dynamic/Registry.cpp1
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp19
4 files changed, 42 insertions, 0 deletions
diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html
index abc2834c4cb..a807672121b 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -2749,6 +2749,15 @@ Usable as: Matcher&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOp
</pre></td></tr>
+<tr><td>Matcher&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('hasTrailingReturn0')"><a name="hasTrailingReturn0Anchor">hasTrailingReturn</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="hasTrailingReturn0"><pre>Matches a function declared with a trailing return type.
+
+Example matches Y (matcher = functionDecl(hasTrailingReturn()))
+int X() {}
+auto Y() -&gt; int {}
+</pre></td></tr>
+
+
<tr><td>Matcher&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('isConstexpr1')"><a name="isConstexpr1Anchor">isConstexpr</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isConstexpr1"><pre>Matches constexpr variable and function declarations.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f66579c87c..e51ce4175e7 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -5893,6 +5893,19 @@ AST_MATCHER(EnumDecl, isScoped) {
return Node.isScoped();
}
+/// \brief Matches a function declared with a trailing return type.
+///
+/// Example matches Y (matcher = functionDecl(hasTrailingReturn()))
+/// \code
+/// int X() {}
+/// auto Y() -> int {}
+/// \endcode
+AST_MATCHER(FunctionDecl, hasTrailingReturn) {
+ if (const auto *F = Node.getType()->getAs<FunctionProtoType>())
+ return F->hasTrailingReturn();
+ return false;
+}
+
} // namespace ast_matchers
} // namespace clang
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 784581fc45b..79aa4e667b3 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -296,6 +296,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(hasTemplateArgument);
REGISTER_MATCHER(hasThen);
REGISTER_MATCHER(hasThreadStorageDuration);
+ REGISTER_MATCHER(hasTrailingReturn);
REGISTER_MATCHER(hasTrueExpression);
REGISTER_MATCHER(hasTypeLoc);
REGISTER_MATCHER(hasUnaryOperand);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index eea4e6f4f23..55c53e66ecd 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2112,5 +2112,24 @@ TEST(IsScopedEnum, MatchesScopedEnum) {
EXPECT_TRUE(notMatches("enum X {};", enumDecl(isScoped())));
}
+TEST(HasTrailingReturn, MatchesTrailingReturn) {
+ EXPECT_TRUE(matches("auto Y() -> int { return 0; }",
+ functionDecl(hasTrailingReturn())));
+ EXPECT_TRUE(matches("auto X() -> int;", functionDecl(hasTrailingReturn())));
+ EXPECT_TRUE(notMatches("int X() { return 0; }",
+ functionDecl(hasTrailingReturn())));
+ EXPECT_TRUE(notMatches("int X();", functionDecl(hasTrailingReturn())));
+ EXPECT_TRUE(notMatchesC("void X();", functionDecl(hasTrailingReturn())));
+}
+
+TEST(HasTrailingReturn, MatchesLambdaTrailingReturn) {
+ EXPECT_TRUE(matches(
+ "auto lambda2 = [](double x, double y) -> double {return x + y;};",
+ functionDecl(hasTrailingReturn())));
+ EXPECT_TRUE(notMatches(
+ "auto lambda2 = [](double x, double y) {return x + y;};",
+ functionDecl(hasTrailingReturn())));
+}
+
} // namespace ast_matchers
} // namespace clang
OpenPOWER on IntegriCloud