File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,15 @@ predicate isTypeZeroInitializable(Type t) {
33
33
t .getUnderlyingType ( ) instanceof ArrayType
34
34
}
35
35
36
+ predicate isCompileTimeEvaluated ( Call call ) {
37
+ call .getTarget ( ) .isConstexpr ( ) and
38
+ forall ( Expr arg | arg = call .getAnArgument ( ) |
39
+ DataFlow:: localExprFlow ( any ( Literal l ) , arg )
40
+ or
41
+ DataFlow:: localExprFlow ( any ( Call c | isCompileTimeEvaluated ( call ) ) , arg )
42
+ )
43
+ }
44
+
36
45
from Variable v
37
46
where
38
47
not isExcluded ( v , ConstPackage:: variableMissingConstexprQuery ( ) ) and
46
55
(
47
56
v .getInitializer ( ) .getExpr ( ) .isConstant ( )
48
57
or
49
- v . getInitializer ( ) . getExpr ( ) . ( Call ) . getTarget ( ) .isConstexpr ( )
58
+ any ( Call call | isCompileTimeEvaluated ( call ) ) = v . getInitializer ( ) .getExpr ( )
50
59
or
51
60
isZeroInitializable ( v )
52
61
or
Original file line number Diff line number Diff line change 10
10
| test.cpp:55:7:55:8 | m2 | Variable m2 could be marked 'constexpr'. |
11
11
| test.cpp:130:7:130:8 | m1 | Variable m1 could be marked 'constexpr'. |
12
12
| test.cpp:141:7:141:8 | m1 | Variable m1 could be marked 'constexpr'. |
13
+ | test.cpp:215:7:215:7 | x | Variable x could be marked 'constexpr'. |
Original file line number Diff line number Diff line change @@ -204,4 +204,14 @@ class ExcludedCases {
204
204
205
205
void operator =(ExcludedCases &) {} // COMPLIANT
206
206
void operator =(ExcludedCases &&) {} // COMPLIANT
207
- };
207
+ };
208
+
209
+
210
+ constexpr int add (int x, int y) {
211
+ return x + y;
212
+ }
213
+
214
+ void fp_reported_in_466 (int p) {
215
+ int x = add (1 ,2 ); // NON_COMPLIANT
216
+ int y = add (1 ,p); // COMPLIANT
217
+ }
You can’t perform that action at this time.
0 commit comments