[cfe-dev] forEachSwitchCase() matcher acting wierd,imho

Malcolm Parsons via cfe-dev cfe-dev at lists.llvm.org
Sat Nov 12 13:04:35 PST 2016


On 12 November 2016 at 11:52, Farzad Sadeghi via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> for this matcher:
> switchStmt(forEachSwitchCase(hasDescendant(breakStmt().bind("bubu"))))

> 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?

forEachSwichCase allows the matcher to match multiple times if there
are multiple switch cases that match.
It doesn't prevent a match if there is a switch case that doesn't match.

To match switch statements where all switch cases have a break
statement you should be able to use
switchStmt(unless(has(compoundStmt(has(switchCase(unless(hasDescendant(breakStmt())))))))).

-- 
Malcolm Parsons



More information about the cfe-dev mailing list