Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4bd03d5

Browse files
committed
C++: Add constexpr support for functions
1 parent 5db38ef commit 4bd03d5

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

cpp/ql/src/semmle/code/cpp/Function.qll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,27 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
103103
function_defaulted(underlyingElement(this))
104104
}
105105

106+
/**
107+
* Holds if this function is declared to be `constexpr`.
108+
*/
109+
predicate isDeclaredConstexpr() {
110+
this.hasSpecifier("declared_constexpr")
111+
}
112+
113+
/**
114+
* Holds if this function is `constexpr`. Normally, this holds if and
115+
* only if `isDeclaredConstexpr()` holds, but in some circumstances
116+
* they differ. For example, with
117+
* ```
118+
* int f(int i) { return 6; }
119+
* template <typename T> constexpr int g(T x) { return f(x); }
120+
* ```
121+
* `g<int>` is declared constexpr, but is not constexpr.
122+
*/
123+
predicate isConstexpr() {
124+
this.hasSpecifier("is_constexpr")
125+
}
126+
106127
/**
107128
* Holds if this function is declared with `__attribute__((naked))` or
108129
* `__declspec(naked)`.

0 commit comments

Comments
 (0)