This commit is contained in:
Geoffrey White 2019-07-05 11:37:00 +01:00
Родитель 629d127174
Коммит 62fb216102
3 изменённых файлов: 16 добавлений и 7 удалений

Просмотреть файл

@ -21,15 +21,25 @@ DoStmt getAFalseLoop() {
}
/**
* Gets a `do` ... `while` loop surrounding a statement.
* Gets a `do` ... `while` loop surrounding a statement. This is blocked by a
* `switch` statement, since a `continue` inside a `switch` inside a loop may be
* jusitifed (`continue` breaks out of the loop whereas `break` only escapes the
* `switch`).
*/
DoStmt enclosingLoop(Stmt s) {
exists(Stmt parent |
parent = s.getParent() and
if parent instanceof Loop then
result = parent
else
result = enclosingLoop(parent))
(
(
parent instanceof Loop and
result = parent
) or (
not parent instanceof Loop and
not parent instanceof SwitchStmt and
result = enclosingLoop(parent)
)
)
)
}
from DoStmt loop, ContinueStmt continue

Просмотреть файл

@ -1,3 +1,2 @@
| 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 |
| 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 |
| 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 |

Просмотреть файл

@ -85,7 +85,7 @@ void test1(int x)
default:
// do [2]
continue; // break out of the loop entirely, skipping [3] [FALSE POSITIVE]
continue; // GOOD; break out of the loop entirely, skipping [3]
};
// do [3]