File tree Expand file tree Collapse file tree
test/query-tests/Likely Bugs/ContinueInFalseLoop Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,15 +21,25 @@ DoStmt getAFalseLoop() {
2121}
2222
2323/**
24- * Gets a `do` ... `while` loop surrounding a statement.
24+ * Gets a `do` ... `while` loop surrounding a statement. This is blocked by a
25+ * `switch` statement, since a `continue` inside a `switch` inside a loop may be
26+ * jusitifed (`continue` breaks out of the loop whereas `break` only escapes the
27+ * `switch`).
2528 */
2629DoStmt enclosingLoop ( Stmt s ) {
2730 exists ( Stmt parent |
2831 parent = s .getParent ( ) and
29- if parent instanceof Loop then
30- result = parent
31- else
32- result = enclosingLoop ( parent ) )
32+ (
33+ (
34+ parent instanceof Loop and
35+ result = parent
36+ ) or (
37+ not parent instanceof Loop and
38+ not parent instanceof SwitchStmt and
39+ result = enclosingLoop ( parent )
40+ )
41+ )
42+ )
3343}
3444
3545from DoStmt loop , ContinueStmt continue
Original file line number Diff line number Diff line change 11| test.cpp:13:4:13:12 | continue; | This 'continue' never re-runs the loop - the $@ is always false. | test.cpp:16:11:16:15 | 0 | loop condition |
22| test.cpp:59:5:59:13 | continue; | This 'continue' never re-runs the loop - the $@ is always false. | test.cpp:62:12:62:16 | 0 | loop condition |
3- | test.cpp:88:4:88:12 | continue; | This 'continue' never re-runs the loop - the $@ is always false. | test.cpp:93:11:93:11 | 0 | loop condition |
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ void test1(int x)
8585 default :
8686 // do [2]
8787
88- continue ; // break out of the loop entirely, skipping [3] [FALSE POSITIVE ]
88+ continue ; // GOOD; break out of the loop entirely, skipping [3]
8989 };
9090
9191 // do [3]
You can’t perform that action at this time.
0 commit comments