File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 57
57
)
58
58
) and
59
59
message = "Controlling expression in switch statement has invariant value."
60
+ or
61
+ exists ( ConditionalExpr conditional |
62
+ conditional .getCondition ( ) = expr and
63
+ (
64
+ conditionAlwaysFalse ( expr ) or
65
+ conditionAlwaysTrue ( expr )
66
+ )
67
+ ) and
68
+ message = "Controlling expression in conditional statement has invariant value."
60
69
) and
61
70
// Exclude cases where the controlling expressions is affected by a macro, because they can appear
62
71
// invariant in a particular invocation, but be variant between invocations.
63
- not expr .isAffectedByMacro ( )
72
+ not (
73
+ expr .isAffectedByMacro ( ) and
74
+ // Permit boolean literal macros
75
+ not expr instanceof BooleanLiteral
76
+ ) and
77
+ // Exclude template variables, because they can be instantiated with different values.
78
+ not expr = any ( TemplateVariable tv ) .getAnInstantiation ( ) .getAnAccess ( )
64
79
select expr , message
Original file line number Diff line number Diff line change 3
3
| test.c:16:9:16:13 | ... > ... | Controlling expression in if statement has invariant value. |
4
4
| test.c:20:20:20:24 | ... < ... | Controlling expression in loop statement has invariant value. |
5
5
| test.c:27:10:27:14 | ... < ... | Controlling expression in loop statement has invariant value. |
6
+ | test.c:37:3:37:6 | 1 | Controlling expression in conditional statement has invariant value. |
7
+ | test.c:38:3:38:3 | 1 | Controlling expression in conditional statement has invariant value. |
Original file line number Diff line number Diff line change @@ -31,4 +31,10 @@ void f3() {
31
31
void f4 () {
32
32
do {
33
33
} while (0u == 1u ); // COMPLIANT - by exception 2
34
+ }
35
+
36
+ void f5 (bool b1 ) {
37
+ true ? 1 : 2 ; // NON_COMPLIANT
38
+ 1 ? 1 : 2 ; // NON_COMPLIANT
39
+ b1 ? 1 : 2 ; // COMPLIANT
34
40
}
You can’t perform that action at this time.
0 commit comments