Skip to content

Commit

Permalink
IdentifierHidden: revert realisitic compile time constant model in la…
Browse files Browse the repository at this point in the history
…mbda hiding

due to performance the simpler heurisitic is better
  • Loading branch information
knewbury01 committed Apr 25, 2024
1 parent a9f55d2 commit 80432d8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import codingstandards.cpp.Customizations
import codingstandards.cpp.Exclusions
import codingstandards.cpp.Scope
import codingstandards.cpp.ConstHelpers
import codingstandards.cpp.Expr

abstract class IdentifierHiddenSharedQuery extends Query { }

Expand Down Expand Up @@ -59,11 +58,11 @@ predicate hiddenInLambda(UserVariable outerDecl, UserVariable innerDecl) {
or
//it is a reference that has been initialized with a constant expression.
outerDecl.getType().stripTopLevelSpecifiers() instanceof ReferenceType and
isCompileTimeEvaluatedExpression(outerDecl.getInitializer().getExpr())
outerDecl.getInitializer().getExpr() instanceof Literal
or
//it const non-volatile integral or enumeration type and has been initialized with a constant expression
// //it const non-volatile integral or enumeration type and has been initialized with a constant expression
outerDecl instanceof NonVolatileConstIntegralOrEnumVariable and
isCompileTimeEvaluatedExpression(outerDecl.getInitializer().getExpr())
outerDecl.getInitializer().getExpr() instanceof Literal
or
//it is constexpr and has no mutable members
outerDecl.isConstexpr() and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +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:158:9:158:10 | a4 | Declaration is hiding declaration $@. | test.cpp:156:14:156:15 | a4 | a4 |
| test.cpp:164:9:164:10 | a5 | Declaration is hiding declaration $@. | test.cpp:162:13:162:14 | a5 | a5 |
2 changes: 1 addition & 1 deletion cpp/common/test/rules/identifierhidden/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void f8() {

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

Expand Down

0 comments on commit 80432d8

Please sign in to comment.