Merge pull request #1012 from ian-semmle/constexpr

C++: Add Variable.isConstexpr()
This commit is contained in:
Nick Rolfe
2019-03-01 14:42:35 +00:00
committed by GitHub
5 changed files with 29 additions and 0 deletions

View File

@@ -39,3 +39,4 @@
* There is a new `Namespace.isInline()` predicate, which holds if the namespace was declared as `inline namespace`.
* The `Expr.isConstant()` predicate now also holds for _address constant expressions_, which are addresses that will be constant after the program has been linked. These address constants do not have a result for `Expr.getValue()`.
* There are new `Function.isDeclaredConstexpr()` and `Function.isConstexpr()` predicates. They can be used to tell whether a function was declared as `constexpr`, and whether it actually is `constexpr`.
* There is a new `Variable.isConstexpr()` predicate. It can be used to tell whether a variable is `constexpr`.

View File

@@ -121,6 +121,13 @@ class Variable extends Declaration, @variable {
result.getLValue() = this.getAnAccess()
}
/**
* Holds if this variable is `constexpr`.
*/
predicate isConstexpr() {
this.hasSpecifier("is_constexpr")
}
/**
* Holds if this variable is constructed from `v` as a result
* of template instantiation. If so, it originates either from a template

View File

@@ -0,0 +1,6 @@
constexpr int var_constexpr = 5;
int var_not_constexpr_initialised = 6;
const int var_not_constexpr_const = 7;
int var_not_constexpr;

View File

@@ -0,0 +1,10 @@
| constexpr.cpp:2:15:2:27 | var_constexpr | true |
| constexpr.cpp:3:5:3:33 | var_not_constexpr_initialised | false |
| constexpr.cpp:4:11:4:33 | var_not_constexpr_const | false |
| constexpr.cpp:5:5:5:21 | var_not_constexpr | false |
| file://:0:0:0:0 | fp_offset | false |
| file://:0:0:0:0 | gp_offset | false |
| file://:0:0:0:0 | overflow_arg_area | false |
| file://:0:0:0:0 | p#0 | false |
| file://:0:0:0:0 | p#0 | false |
| file://:0:0:0:0 | reg_save_area | false |

View File

@@ -0,0 +1,5 @@
import cpp
from Variable v
select v,
any(boolean b | if v.isConstexpr() then b = true else b = false)