[cfe-dev] forEachSwitchCase() matcher acting wierd,imho
Aaron Ballman via cfe-dev
cfe-dev at lists.llvm.org
Sat Nov 12 13:03:57 PST 2016
On Sat, Nov 12, 2016 at 6:52 AM, Farzad Sadeghi via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> here's the tst function:
> ---------------------------------------------------------------
> void testFunc (void)
> {
> int level = 10;
> switch (level)
> {
> case 1:
> {level++;
> break;}
> case 2:
> {level = 10;}
> case 3:
> {level = 1U;}
> }
> }
> -----------------------------------------------------------
> for this matcher:
> switchStmt(forEachSwitchCase(hasDescendant(breakStmt().bind("bubu"))))
> clang-query returns this:
> Match #1:
>
> /home/bloodstalker/devi/hell1/test4.c:9:18: note: "bubu" binds here
> break;}
> ^~~~~
> /home/bloodstalker/devi/hell1/test4.c:5:9: note: "root" binds here
> switch (level)
> ^~~~~~~~~~~~~~
> 1 match.
>
> now,my question is, shouldn't clang-query just not match anything,
> since each switchCase clearly does not have a descendant breakStmt or
> am I misunderstanding something?
forEachSwitchCase() is something that checks each case label in a
switch statement against the argument to the matcher. This explains
why you match one out of the three case labels -- each one is checked
individually against hasDescendant(breakStmt()).
HTH!
~Aaron
More information about the cfe-dev
mailing list