Skip to content

Commit 30aa044

Browse files
committed
IdentifierHidden: reduce FN case and remove redundant testcase
1 parent 69d18f2 commit 30aa044

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

cpp/common/src/codingstandards/cpp/rules/identifierhidden/IdentifierHidden.qll

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ abstract class IdentifierHiddenSharedQuery extends Query { }
1313
Query getQuery() { result instanceof IdentifierHiddenSharedQuery }
1414

1515
/**
16-
* a `IntegralOrEnumType` that is nonvolatile and const
16+
* a `Variable` that is nonvolatile and const
17+
* and of type `IntegralOrEnumType`
1718
*/
18-
class NonVolatileConstIntegralOrEnumType extends IntegralOrEnumType {
19-
NonVolatileConstIntegralOrEnumType() {
19+
class NonVolatileConstIntegralOrEnumVariable extends Variable {
20+
NonVolatileConstIntegralOrEnumVariable() {
2021
not this.isVolatile() and
21-
this.isConst()
22+
this.isConst() and
23+
this.getUnspecifiedType() instanceof IntegralOrEnumType
2224
}
2325
}
2426

@@ -59,7 +61,7 @@ predicate hiddenInLambda(UserVariable outerDecl, UserVariable innerDecl) {
5961
exists(outerDecl.getInitializer().getExpr().getValue())
6062
or
6163
//it const non-volatile integral or enumeration type and has been initialized with a constant expression
62-
outerDecl.getType() instanceof NonVolatileConstIntegralOrEnumType and
64+
outerDecl instanceof NonVolatileConstIntegralOrEnumVariable and
6365
exists(outerDecl.getInitializer().getExpr().getValue())
6466
or
6567
//it is constexpr and has no mutable members

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

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
| test.cpp:142:9:142:10 | a1 | Declaration is hiding declaration $@. | test.cpp:140:14:140:15 | a1 | a1 |
1616
| test.cpp:147:9:147:10 | a2 | Declaration is hiding declaration $@. | test.cpp:145:20:145:21 | a2 | a2 |
1717
| test.cpp:152:9:152:10 | a3 | Declaration is hiding declaration $@. | test.cpp:150:17:150:18 | a3 | a3 |
18+
| test.cpp:164:9:164:10 | a5 | Declaration is hiding declaration $@. | test.cpp:162:13:162:14 | a5 | a5 |

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

+1-9
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void f8() {
161161

162162
const int a5 = 10;
163163
auto lambda5 = []() {
164-
int a5 = a5 + 1; // NON_COMPLIANT[FALSE_NEGATIVE] - Lambda can access const
164+
int a5 = a5 + 1; // NON_COMPLIANT - Lambda can access const
165165
// non-volatile integral or enumeration type initialized
166166
// with constant expression.
167167
};
@@ -172,12 +172,4 @@ void f8() {
172172
a6 + 1; // COMPLIANT - Lambda cannot access const volatile integral or
173173
// enumeration type initialized with constant expression.
174174
};
175-
}
176-
177-
void f9() {
178-
auto lambda1 = []() {
179-
int a1 = 10; // COMPLIANT
180-
};
181-
182-
int a1 = 10;
183175
}

0 commit comments

Comments
 (0)