[PATCH] D42213: [ASTMatchers] [NFC] Fix code examples

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 19 13:40:22 PST 2018


MaskRay added a comment.

In https://reviews.llvm.org/D42213#982261, @aaron.ballman wrote:

> In https://reviews.llvm.org/D42213#982256, @MaskRay wrote:
>
> > I am also not sure about this function:  line 3548
> >
> >   /// \brief Matches \c FunctionDecls and \c FunctionProtoTypes that have a
> >   /// specific parameter count.
> >   ///
> >   /// Given
> >   /// \code
> >   ///   void f(int i) {}
> >   ///   void g(int i, int j) {}
> >   ///   void h(int i, int j);
> >   ///   void j(int i);
> >   ///   void k(int x, int y, int z, ...);
> >   /// \endcode
> >   /// functionDecl(parameterCountIs(2))
> >   ///   matches void g(int i, int j) {}
> >   /// functionProtoType(parameterCountIs(2))
> >   ///   matches void h(int i, int j)
> >   /// functionProtoType(parameterCountIs(3))
> >   ///   matches void k(int x, int y, int z, ...);
> >   AST_POLYMORPHIC_MATCHER_P(parameterCountIs,
> >                             AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
> >                                                             FunctionProtoType),
> >   }
> >
> >
> > Both `functionDecl` and `functionProtoType` match these functions as long as the parameter count is matched.
> >
> >   % echo 'match functionDecl()'|clang-query =(printf 'void f(){}') -- -xc++
> >   % echo 'match functionProtoType()'|clang-query =(printf 'void f(){}') -- -xc++
> >
>
>
> I'm not certain I'm following along. The quoted matcher is for `parameterCountIs()`, but the test code you've posted doesn't use that matcher. However, the quoted comment seems like it's wrong: `functionDecl(parameterCountIs(2))` should match both g() and h(), not just g(), I believe.


Yes, I was asking about this because the results seemed to be wrong. I should have used `parameterCountIs()` to reduce the confusion :) I'll leave them untouched.


Repository:
  rC Clang

https://reviews.llvm.org/D42213





More information about the cfe-commits mailing list