[cfe-dev] AST Matcher matches InitListExpr child twice
Ben Liblit via cfe-dev
cfe-dev at lists.llvm.org
Sat Jun 10 06:31:08 PDT 2017
Consider the following C++11 (or later) code fragment, which uses an
initialization list that contains a function call:
int f();
int i {f()};
The AST for that initialization list consists of an InitListExpr with a
single CallExpr child:
InitListExpr 0x2df2b80 'int'
`-CallExpr 0x2df2b10 'int'
`-ImplicitCastExpr 0x2df2af8 ...
`-DeclRefExpr 0x2df2aa0 ...
If I use the Clang AST Matcher API to match on InitListExpr, then I get
one match as expected. However, if I match on CallExpr, then the single
CallExpr in the above AST is matched *twice*. Anything below that
CallExpr node is also matched twice; for example, I'd get two matches
for the DeclRefExpr if that's what my AST Matcher were looking for.
This is definitely a problem for my code, and would seem to be a bug in
general. Surely that's not the intended behavior, is it?
Attached below is a small test program, "visit.cc", that matches and
dumps out InitListExpr and CallExpr nodes in the AST. Running this on
my above example clearly shows that only one InitListExpr is matched,
but a single CallExpr (at a single memory address) is matched *twice*.
Should I file this glitch as a Clang bug report rather than describing
it on this mailing list? Is there a reasonable workaround until this
bug can be properly fixed?
Thanks,
Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: visit.cc
Type: text/x-c++src
Size: 1409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170610/f2c23ddd/attachment.cc>
More information about the cfe-dev
mailing list