alexey.knyshev added inline comments.
================
Comment at: lib/StaticAnalyzer/Checkers/LabelInsideSwitchChecker.cpp:87
+ BugReporter &BR) const {
+ auto LabelStmt = stmt(hasDescendant(switchStmt(
+ eachOf(has(compoundStmt(forEach(labelStmt().bind("label")))),
----------------
a.sidorin wrote:
> alexey.knyshev wrote:
> > Looks like I have to use `forEachDescendant` instead of `hasDescendant`.
> > Please, comment!
> 1. Yes, `hasDescendant()` will give you only single match.
> `forEachDescendant()` will continue matching after match found and that is
> what we should do here.
> 2. Maybe we can just use
> stmt(forEachDescendant(switchStmt(forEachDescendant(labelStmt()))))? We don't
> distinguish "label" and "label_in_case" anyway. Also, current matcher will
> ignore deeply-nested switches:
> ```
> switch (x) }
> case 1: {
> {{ label: }} // ignored
> }
> }
> ```
> Is that intentional?
1. Thanks, got it.
2. I've used `eachOf` for matching 2 different cases:
- Label under case stmt such as:
```
switch (x) {
case 1:
someCodeHere;
cas: // missprint
... // other cases
}
```
- And label under switch compound stmt:
```
switch (x) {
cas: blabla; // this label is not a child of any case stmt
case 3: ...
...
// etc
```
On the other hand I would like to avoid matching deeply-nested labels inside
switch compound stmt for reducing false-positives probability. Actually I'm not
sure in my assumption.
Repository:
rC Clang
https://reviews.llvm.org/D40715
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits