diff options
| author | Aaron Ballman <aaron@aaronballman.com> | 2016-01-18 20:37:44 +0000 |
|---|---|---|
| committer | Aaron Ballman <aaron@aaronballman.com> | 2016-01-18 20:37:44 +0000 |
| commit | eb85b04c7eccad93706d7e7e319a34597f521ac6 (patch) | |
| tree | 56b9aa57cf8c7ed6c72a3820cb4eb4e17eed8d99 /clang | |
| parent | 5e46adb09a6aac616e3b469d3bb6682fa4160d2b (diff) | |
| download | bcm5719-llvm-eb85b04c7eccad93706d7e7e319a34597f521ac6.tar.gz bcm5719-llvm-eb85b04c7eccad93706d7e7e319a34597f521ac6.zip | |
Add an AST matcher for checking whether a function is defaulted.
Patch by Jonathan Coe.
llvm-svn: 258072
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/docs/LibASTMatchersReference.html | 11 | ||||
| -rw-r--r-- | clang/include/clang/ASTMatchers/ASTMatchers.h | 13 | ||||
| -rw-r--r-- | clang/lib/ASTMatchers/Dynamic/Registry.cpp | 1 | ||||
| -rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 7 |
4 files changed, 32 insertions, 0 deletions
diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index d452c783a80..7f212620b18 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -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. diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 1306706a671..f0d82275ba8 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -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: diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp index 9ecc4922da8..e2c9a475691 100644 --- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -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); diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index c76100a433c..5fde0ff504f 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -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()))); |

