Skip to content

Commit 22a80f6

Browse files
committed
IdentifierHidden: use improved constant expression logic
1 parent 24247d2 commit 22a80f6

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import codingstandards.cpp.Customizations
77
import codingstandards.cpp.Exclusions
88
import codingstandards.cpp.Scope
99
import codingstandards.cpp.ConstHelpers
10+
import codingstandards.cpp.Expr
1011

1112
abstract class IdentifierHiddenSharedQuery extends Query { }
1213

@@ -58,11 +59,11 @@ predicate hiddenInLambda(UserVariable outerDecl, UserVariable innerDecl) {
5859
or
5960
//it is a reference that has been initialized with a constant expression.
6061
outerDecl.getType().stripTopLevelSpecifiers() instanceof ReferenceType and
61-
exists(outerDecl.getInitializer().getExpr().getValue())
62+
isCompileTimeEvaluatedExpression(outerDecl.getInitializer().getExpr())
6263
or
6364
//it const non-volatile integral or enumeration type and has been initialized with a constant expression
6465
outerDecl instanceof NonVolatileConstIntegralOrEnumVariable and
65-
exists(outerDecl.getInitializer().getExpr().getValue())
66+
isCompileTimeEvaluatedExpression(outerDecl.getInitializer().getExpr())
6667
or
6768
//it is constexpr and has no mutable members
6869
outerDecl.isConstexpr() and

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
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:158:9:158:10 | a4 | Declaration is hiding declaration $@. | test.cpp:156:14:156:15 | a4 | a4 |
1819
| 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void f8() {
155155

156156
const int &a4 = a3;
157157
auto lambda4 = []() {
158-
int a4 = a4 + 1; // NON_COMPLIANT[FALSE_NEGATIVE] - Lambda can access
158+
int a4 = a4 + 1; // NON_COMPLIANT - Lambda can access
159159
// reference initialized with constant expression.
160160
};
161161

0 commit comments

Comments
 (0)