[PATCH] D25600: [ASTMatcher] Add isStaticDataMember matcher for varDecl.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 14 07:39:06 PDT 2016


aaron.ballman added inline comments.


================
Comment at: include/clang/ASTMatchers/ASTMatchers.h:3005
+/// \endcode
+AST_MATCHER(VarDecl, isStaticDataMember) {
+  return Node.isStaticDataMember();
----------------
hokein wrote:
> aaron.ballman wrote:
> > How does this differ from the existing matcher `hasStaticStorageDuration()` over a `fieldDecl()`?
> `fieldDecl` document says that fieldDecl is "an instance of this class is created by Sema::ActOnField to
> represent a member of a struct/union/class.". So for static class members, they should not belong to `fieldDecl` as they are not bound to class instances.
>  
> Technically, we can't apply `hasStaticStorageDuration()` and `isStaticStorageClass` over a `fieldDecl`.
>  
That's a really good point, but the question still remains: since we have `hasStaticStorageDuration()` already, can we find a way to use that same matcher rather than introduce a new matcher under a new name that does the same thing?

This time I tested a matcher, and found that you get the correct behavior from `varDecl(hasStaticStorageDuration(), hasParent(recordDecl()))`.

I think this is especially important to try to do because we have `hasStaticStorageDuration()` and `isStaticStorageClass()`, so adding `isStaticDataMember()` adds a third option to possibly confuse users.


https://reviews.llvm.org/D25600





More information about the cfe-commits mailing list