forked from OSchip/llvm-project
Add an AST matcher for checking whether a function is defaulted.
Patch by Jonathan Coe. llvm-svn: 258072
This commit is contained in:
parent
5e46adb09a
commit
eb85b04c7e
|
@ -2184,6 +2184,17 @@ Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDec
|
|||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></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<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></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.
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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())));
|
||||
|
|
Loading…
Reference in New Issue