Skip to content

Commit 80432d8

Browse files
committed
IdentifierHidden: revert realisitic compile time constant model in lambda hiding
due to performance the simpler heurisitic is better
1 parent a9f55d2 commit 80432d8

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import codingstandards.cpp.Customizations
77
import codingstandards.cpp.Exclusions
88
import codingstandards.cpp.Scope
99
import codingstandards.cpp.ConstHelpers
10-
import codingstandards.cpp.Expr
1110

1211
abstract class IdentifierHiddenSharedQuery extends Query { }
1312

@@ -59,11 +58,11 @@ predicate hiddenInLambda(UserVariable outerDecl, UserVariable innerDecl) {
5958
or
6059
//it is a reference that has been initialized with a constant expression.
6160
outerDecl.getType().stripTopLevelSpecifiers() instanceof ReferenceType and
62-
isCompileTimeEvaluatedExpression(outerDecl.getInitializer().getExpr())
61+
outerDecl.getInitializer().getExpr() instanceof Literal
6362
or
64-
//it const non-volatile integral or enumeration type and has been initialized with a constant expression
63+
// //it const non-volatile integral or enumeration type and has been initialized with a constant expression
6564
outerDecl instanceof NonVolatileConstIntegralOrEnumVariable and
66-
isCompileTimeEvaluatedExpression(outerDecl.getInitializer().getExpr())
65+
outerDecl.getInitializer().getExpr() instanceof Literal
6766
or
6867
//it is constexpr and has no mutable members
6968
outerDecl.isConstexpr() and

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

-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +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:158:9:158:10 | a4 | Declaration is hiding declaration $@. | test.cpp:156:14:156:15 | a4 | a4 |
1918
| 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-1
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 - Lambda can access
158+
int a4 = a4 + 1; // NON_COMPLIANT[FALSE_NEGATIVE] - Lambda can access
159159
// reference initialized with constant expression.
160160
};
161161

0 commit comments

Comments
 (0)