Skip to content

Commit 2a5964b

Browse files
committed
IdentifierHiding: Include catchblock parameters
1 parent adc818b commit 2a5964b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

cpp/common/src/codingstandards/cpp/Scope.qll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ private Element getParentScope(Element e) {
4242
then result = e.getParentScope()
4343
else (
4444
// Statements do no have a parent scope, so return the enclosing block.
45-
result = e.(Stmt).getEnclosingBlock() or result = e.(Expr).getEnclosingBlock()
45+
result = e.(Stmt).getEnclosingBlock()
46+
or
47+
result = e.(Expr).getEnclosingBlock()
48+
or
49+
// Catch block parameters don't have an enclosing scope, so attach them to the
50+
// the block itself
51+
exists(CatchBlock cb |
52+
e = cb.getParameter() and
53+
result = cb
54+
)
4655
)
4756
}
4857

cpp/common/test/rules/identifierhidden/IdentifierHidden.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
| test.cpp:65:11:65:11 | i | Variable is hiding variable $@. | test.cpp:61:7:61:7 | i | i |
99
| test.cpp:67:9:67:9 | i | Variable is hiding variable $@. | test.cpp:61:7:61:7 | i | i |
1010
| test.cpp:70:12:70:12 | i | Variable is hiding variable $@. | test.cpp:61:7:61:7 | i | i |
11+
| test.cpp:75:16:75:16 | i | Variable is hiding variable $@. | test.cpp:61:7:61:7 | i | i |

cpp/common/test/rules/identifierhidden/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ void test_scope_order() {
7272

7373
try {
7474

75-
} catch (int i) { // NON_COMPLIANT[FALSE_NEGATIVE]
75+
} catch (int i) { // NON_COMPLIANT
7676
}
7777
}

0 commit comments

Comments
 (0)