Skip to content

Commit

Permalink
IdentifierHidden: reduce FN case and remove redundant testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
knewbury01 committed Apr 5, 2024
1 parent 69d18f2 commit 30aa044
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ abstract class IdentifierHiddenSharedQuery extends Query { }
Query getQuery() { result instanceof IdentifierHiddenSharedQuery }

/**
* a `IntegralOrEnumType` that is nonvolatile and const
* a `Variable` that is nonvolatile and const
* and of type `IntegralOrEnumType`
*/
class NonVolatileConstIntegralOrEnumType extends IntegralOrEnumType {
NonVolatileConstIntegralOrEnumType() {
class NonVolatileConstIntegralOrEnumVariable extends Variable {
NonVolatileConstIntegralOrEnumVariable() {
not this.isVolatile() and
this.isConst()
this.isConst() and
this.getUnspecifiedType() instanceof IntegralOrEnumType
}
}

Expand Down Expand Up @@ -59,7 +61,7 @@ predicate hiddenInLambda(UserVariable outerDecl, UserVariable innerDecl) {
exists(outerDecl.getInitializer().getExpr().getValue())
or
//it const non-volatile integral or enumeration type and has been initialized with a constant expression
outerDecl.getType() instanceof NonVolatileConstIntegralOrEnumType and
outerDecl instanceof NonVolatileConstIntegralOrEnumVariable and
exists(outerDecl.getInitializer().getExpr().getValue())
or
//it is constexpr and has no mutable members
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
| test.cpp:142:9:142:10 | a1 | Declaration is hiding declaration $@. | test.cpp:140:14:140:15 | a1 | a1 |
| test.cpp:147:9:147:10 | a2 | Declaration is hiding declaration $@. | test.cpp:145:20:145:21 | a2 | a2 |
| test.cpp:152:9:152:10 | a3 | Declaration is hiding declaration $@. | test.cpp:150:17:150:18 | a3 | a3 |
| test.cpp:164:9:164:10 | a5 | Declaration is hiding declaration $@. | test.cpp:162:13:162:14 | a5 | a5 |
10 changes: 1 addition & 9 deletions cpp/common/test/rules/identifierhidden/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void f8() {

const int a5 = 10;
auto lambda5 = []() {
int a5 = a5 + 1; // NON_COMPLIANT[FALSE_NEGATIVE] - Lambda can access const
int a5 = a5 + 1; // NON_COMPLIANT - Lambda can access const
// non-volatile integral or enumeration type initialized
// with constant expression.
};
Expand All @@ -172,12 +172,4 @@ void f8() {
a6 + 1; // COMPLIANT - Lambda cannot access const volatile integral or
// enumeration type initialized with constant expression.
};
}

void f9() {
auto lambda1 = []() {
int a1 = 10; // COMPLIANT
};

int a1 = 10;
}

0 comments on commit 30aa044

Please sign in to comment.