mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Merge pull request #1012 from ian-semmle/constexpr
C++: Add Variable.isConstexpr()
This commit is contained in:
@@ -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`.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 |
|
||||
@@ -0,0 +1,5 @@
|
||||
import cpp
|
||||
|
||||
from Variable v
|
||||
select v,
|
||||
any(boolean b | if v.isConstexpr() then b = true else b = false)
|
||||
Reference in New Issue
Block a user