]> granicus.if.org Git - clang/commitdiff
Add an AST matcher for checking whether a function is defaulted.
authorAaron Ballman <aaron@aaronballman.com>
Mon, 18 Jan 2016 20:37:44 +0000 (20:37 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Mon, 18 Jan 2016 20:37:44 +0000 (20:37 +0000)
Patch by Jonathan Coe.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258072 91177308-0d34-0410-b5e6-96231b3b80d8

docs/LibASTMatchersReference.html
include/clang/ASTMatchers/ASTMatchers.h
lib/ASTMatchers/Dynamic/Registry.cpp
unittests/ASTMatchers/ASTMatchersTest.cpp

index d452c783a800783909da18f3d1e0a5cea574067a..7f212620b185f1ff6ef12ae11f292e3cb0240c08 100644 (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.
 
index 1306706a6710e7680f983e1d428a6e985d439f04..f0d82275ba8be0866578dfd2aafddae4277c389c 100644 (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:
index 9ecc4922da86450bd13f930d42064a4d174dfed3..e2c9a475691eb34c3de6a33efc57437c17704ee2 100644 (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);
index c76100a433cbf99b648dd893120cb4eb9215d65c..5fde0ff504f8303f69a7743c308a4e9296d612e3 100644 (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())));