Add an AST matcher for checking whether a function is defaulted.

Patch by Jonathan Coe.

llvm-svn: 258072
This commit is contained in:
Aaron Ballman 2016-01-18 20:37:44 +00:00
parent 5e46adb09a
commit eb85b04c7e
4 changed files with 32 additions and 0 deletions

View File

@ -2184,6 +2184,17 @@ Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDec
</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('isDefaulted0')"><a name="isDefaulted0Anchor">isDefaulted</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isDefaulted0"><pre>Matches defaulted function declarations.
Given:
class A { ~A(); };
class B { ~B() = default; };
functionDecl(isDefaulted())
matches the declaration of ~B, but not ~A.
</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('isDeleted0')"><a name="isDeleted0Anchor">isDeleted</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isDeleted0"><pre>Matches deleted function declarations.

View File

@ -2993,6 +2993,19 @@ AST_MATCHER(FunctionDecl, isDeleted) {
return Node.isDeleted();
}
/// \brief Matches defaulted function declarations.
///
/// Given:
/// \code
/// class A { ~A(); };
/// class B { ~B() = default; };
/// \endcode
/// functionDecl(isDefaulted())
/// matches the declaration of ~B, but not ~A.
AST_MATCHER(FunctionDecl, isDefaulted) {
return Node.isDefaulted();
}
/// \brief Matches functions that have a non-throwing exception specification.
///
/// Given:

View File

@ -270,6 +270,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(isConstQualified);
REGISTER_MATCHER(isCopyConstructor);
REGISTER_MATCHER(isDefaultConstructor);
REGISTER_MATCHER(isDefaulted);
REGISTER_MATCHER(isDefinition);
REGISTER_MATCHER(isDeleted);
REGISTER_MATCHER(isExceptionVariable);

View File

@ -1814,6 +1814,13 @@ TEST(IsExternC, MatchesExternCFunctionDeclarations) {
EXPECT_TRUE(notMatches("void f() {}", functionDecl(isExternC())));
}
TEST(IsDefaulted, MatchesDefaultedFunctionDeclarations) {
EXPECT_TRUE(
notMatches("class A { ~A(); };", functionDecl(hasName("A"), isDefaulted())));
EXPECT_TRUE(matches("class B { ~B() = default; };",
functionDecl(hasName("B"), isDefaulted())));
}
TEST(IsDeleted, MatchesDeletedFunctionDeclarations) {
EXPECT_TRUE(
notMatches("void Func();", functionDecl(hasName("Func"), isDeleted())));