aaron.ballman accepted this revision. aaron.ballman added a comment. LGTM!
================ Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:6406-6414 +/// Matches reference `TypeLoc`s. +/// +/// Given +/// \code +/// int x = 3; +/// int& xx = x; +/// \endcode ---------------- jcking1034 wrote: > jcking1034 wrote: > > aaron.ballman wrote: > > > I'd appreciate more documentation on whether this is expected to match > > > both lvalue and rvalue references. I suppose there's a secondary question > > > of whether this matches member functions too: > > > ``` > > > struct S { > > > void func() &; // Can this match this as a reference type loc? > > > }; > > > ``` > > I've added an example to clarify that this matches both lvalue and rvalue > > references. Having some trouble addressing your second point, but will keep > > playing around with it. > After looking into it, it seems that this matcher will not match > ref-qualified member functions. Essentially, this node isn't represented in a > way that allows for it to be matched by `referenceTypeLoc`. > > For a more detailed explaination: In this example, we are able to use > `cxxMethodDecl` to match `void func() &`. If we wished to match the `Type` of > the member function, we could use > `cxxMethodDecl(hasType(functionProtoType().bind("t")))`, and from the > `FunctionProtoType` node you could determine if the function is ref-qualified > through a call to `getRefQualifier` > (https://clang.llvm.org/doxygen/classclang_1_1FunctionProtoType.html). It's > not possible to match using > `cxxMethodDecl(hasType(referenceType().bind("t")))`. So it seems that the > type of the member function is not a reference type, but instead a > `FunctionProtoType` from which you'd programmatically have to determine if > it's a reference type. In the realm of `TypeLoc`s, there is no `TypeLoc` that > corresponds to the `FunctionProtoType` node, and so the best you could do may > be something like > `cxxMethodDecl(hasTypeLoc(loc(functionProtoType().bind("t"))))` and > programmatically analyzing the bound node. For reference, please see > https://godbolt.org/z/qxsEb6a5Y. Thank you for the detailed explanation! I think the current behavior is fine. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D111242/new/ https://reviews.llvm.org/D111242 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits