[PATCH] D16215: ASTMatchers: enable hasBody() matcher for FunctionDecls

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 19 07:47:06 PST 2016


aaron.ballman added inline comments.

================
Comment at: include/clang/ASTMatchers/ASTMatchers.h:3118
@@ -3119,1 +3117,3 @@
+/// \brief Matches a 'for', 'while', 'do while' statement or a function
+/// declaration that has a given body.
 ///
----------------
s/declaration/definition.

================
Comment at: include/clang/ASTMatchers/ASTMatchersInternal.h:1590
@@ +1589,3 @@
+struct GetBodyMatcher {
+static const Stmt *get(const Ty &Node) {
+  return Node.getBody();
----------------
Indentation here is incorrect, you should run clang-format over the patch.

================
Comment at: lib/ASTMatchers/ASTMatchersInternal.cpp:342
@@ -341,1 +341,3 @@
 
+template <>
+const Stmt *GetBodyMatcher<FunctionDecl>::get(const FunctionDecl &Node) {
----------------
The specialization should live in the header file, not the source file.

================
Comment at: lib/ASTMatchers/ASTMatchersInternal.cpp:344
@@ +343,3 @@
+const Stmt *GetBodyMatcher<FunctionDecl>::get(const FunctionDecl &Node) {
+  return Node.isThisDeclarationADefinition() ? Node.getBody() : NULL;
+}
----------------
I would use `Node.doesThisDeclarationHaveABody()` instead; otherwise this will match definitions that are explicitly deleted, which isn't particularly useful.


http://reviews.llvm.org/D16215





More information about the cfe-commits mailing list