Author: aaronballman Date: Mon Jan 18 14:37:44 2016 New Revision: 258072 URL: http://llvm.org/viewvc/llvm-project?rev=258072&view=rev Log: Add an AST matcher for checking whether a function is defaulted.
Patch by Jonathan Coe. Modified: cfe/trunk/docs/LibASTMatchersReference.html cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Modified: cfe/trunk/docs/LibASTMatchersReference.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=258072&r1=258071&r2=258072&view=diff ============================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html (original) +++ cfe/trunk/docs/LibASTMatchersReference.html Mon Jan 18 14:37:44 2016 @@ -2184,6 +2184,17 @@ Usable as: Matcher<<a href="http://cla </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. Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=258072&r1=258071&r2=258072&view=diff ============================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original) +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Jan 18 14:37:44 2016 @@ -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: Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=258072&r1=258071&r2=258072&view=diff ============================================================================== --- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original) +++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Mon Jan 18 14:37:44 2016 @@ -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); Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=258072&r1=258071&r2=258072&view=diff ============================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original) +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Mon Jan 18 14:37:44 2016 @@ -1814,6 +1814,13 @@ TEST(IsExternC, MatchesExternCFunctionDe 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()))); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits