summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/LibASTMatchersReference.html9
-rw-r--r--include/clang/ASTMatchers/ASTMatchers.h11
-rw-r--r--lib/ASTMatchers/Dynamic/Registry.cpp1
-rw-r--r--unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp21
4 files changed, 42 insertions, 0 deletions
diff --git a/docs/LibASTMatchersReference.html b/docs/LibASTMatchersReference.html
index bcd236adf5..ed1ec193d8 100644
--- a/docs/LibASTMatchersReference.html
+++ b/docs/LibASTMatchersReference.html
@@ -2307,6 +2307,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_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;</td><td class="name" onclick="toggle('hasDefinition0')"><a name="hasDefinition0Anchor">hasDefinition</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="hasDefinition0"><pre>Matches a class declaration that is defined.
+
+Example matches x (matcher = cxxRecordDecl(hasDefinition()))
+class x {};
+class y;
+</pre></td></tr>
+
+
<tr><td>Matcher&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>&gt;</td><td class="name" onclick="toggle('isDerivedFrom1')"><a name="isDerivedFrom1Anchor">isDerivedFrom</a></td><td>std::string BaseName</td></tr>
<tr><td colspan="4" class="doc" id="isDerivedFrom1"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)).
</pre></td></tr>
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h
index 93fe9fbb9d..64e7e908d5 100644
--- a/include/clang/ASTMatchers/ASTMatchers.h
+++ b/include/clang/ASTMatchers/ASTMatchers.h
@@ -5853,6 +5853,17 @@ AST_MATCHER_P(CXXNewExpr, hasArraySize, internal::Matcher<Expr>, InnerMatcher) {
InnerMatcher.matches(*Node.getArraySize(), Finder, Builder);
}
+/// \brief Matches a class declaration that is defined.
+///
+/// Example matches x (matcher = cxxRecordDecl(hasDefinition()))
+/// \code
+/// class x {};
+/// class y;
+/// \endcode
+AST_MATCHER(CXXRecordDecl, hasDefinition) {
+ return Node.hasDefinition();
+}
+
} // namespace ast_matchers
} // namespace clang
diff --git a/lib/ASTMatchers/Dynamic/Registry.cpp b/lib/ASTMatchers/Dynamic/Registry.cpp
index 52b8d3a6c9..2b7bb7a212 100644
--- a/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -250,6 +250,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(hasDeclContext);
REGISTER_MATCHER(hasDeducedType);
REGISTER_MATCHER(hasDefaultArgument);
+ REGISTER_MATCHER(hasDefinition);
REGISTER_MATCHER(hasDescendant);
REGISTER_MATCHER(hasDestinationType);
REGISTER_MATCHER(hasDynamicExceptionSpec);
diff --git a/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index f6b217c0cb..7e7d027071 100644
--- a/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2008,5 +2008,26 @@ TEST(HasArraySize, Basic) {
cxxNewExpr(hasArraySize(integerLiteral(equals(10))))));
}
+TEST(HasDefinition, MatchesStructDefinition) {
+ EXPECT_TRUE(matches("struct x {};",
+ cxxRecordDecl(hasDefinition())));
+ EXPECT_TRUE(notMatches("struct x;",
+ cxxRecordDecl(hasDefinition())));
+}
+
+TEST(HasDefinition, MatchesClassDefinition) {
+ EXPECT_TRUE(matches("class x {};",
+ cxxRecordDecl(hasDefinition())));
+ EXPECT_TRUE(notMatches("class x;",
+ cxxRecordDecl(hasDefinition())));
+}
+
+TEST(HasDefinition, MatchesUnionDefinition) {
+ EXPECT_TRUE(matches("union x {};",
+ cxxRecordDecl(hasDefinition())));
+ EXPECT_TRUE(notMatches("union x;",
+ cxxRecordDecl(hasDefinition())));
+}
+
} // namespace ast_matchers
} // namespace clang