diff --git a/cpp/common/src/codingstandards/cpp/rules/identifierhidden/IdentifierHidden.qll b/cpp/common/src/codingstandards/cpp/rules/identifierhidden/IdentifierHidden.qll index 26cd40747..820bb986f 100644 --- a/cpp/common/src/codingstandards/cpp/rules/identifierhidden/IdentifierHidden.qll +++ b/cpp/common/src/codingstandards/cpp/rules/identifierhidden/IdentifierHidden.qll @@ -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 } } @@ -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 diff --git a/cpp/common/test/rules/identifierhidden/IdentifierHidden.expected b/cpp/common/test/rules/identifierhidden/IdentifierHidden.expected index 518d21ace..1b0d94d83 100644 --- a/cpp/common/test/rules/identifierhidden/IdentifierHidden.expected +++ b/cpp/common/test/rules/identifierhidden/IdentifierHidden.expected @@ -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 | diff --git a/cpp/common/test/rules/identifierhidden/test.cpp b/cpp/common/test/rules/identifierhidden/test.cpp index 71b9f283c..ede4bb24d 100644 --- a/cpp/common/test/rules/identifierhidden/test.cpp +++ b/cpp/common/test/rules/identifierhidden/test.cpp @@ -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. }; @@ -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; } \ No newline at end of file