Skip to content

Commit 4ce896b

Browse files
authored
Merge pull request github#3378 from matt-gretton-dann/codeql-c-extractor/49-consteval
Add support for C++20's consteval specifier
2 parents c8292e4 + 7d60509 commit 4ce896b

File tree

5 files changed

+14
-0
lines changed

5 files changed

+14
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
103103

104104
/**
105105
* Holds if this function is declared to be `constexpr`.
106+
*
107+
* Note that this does not hold if the function has been declared
108+
* `consteval`.
106109
*/
107110
predicate isDeclaredConstexpr() { this.hasSpecifier("declared_constexpr") }
108111

@@ -115,9 +118,16 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
115118
* template <typename T> constexpr int g(T x) { return f(x); }
116119
* ```
117120
* `g<int>` is declared constexpr, but is not constexpr.
121+
*
122+
* Will also hold if this function is `consteval`.
118123
*/
119124
predicate isConstexpr() { this.hasSpecifier("is_constexpr") }
120125

126+
/**
127+
* Holds if this function is declared to be `consteval`.
128+
*/
129+
predicate isConsteval() { this.hasSpecifier("is_consteval") }
130+
121131
/**
122132
* Holds if this function is declared with `__attribute__((naked))` or
123133
* `__declspec(naked)`.

cpp/ql/test/library-tests/clang_ms/element.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
| file://:0:0:0:0 | implicit_int |
9292
| file://:0:0:0:0 | inline |
9393
| file://:0:0:0:0 | int |
94+
| file://:0:0:0:0 | is_consteval |
9495
| file://:0:0:0:0 | is_constexpr |
9596
| file://:0:0:0:0 | is_thread_local |
9697
| file://:0:0:0:0 | long |

cpp/ql/test/library-tests/conditions/elements.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
| file://:0:0:0:0 | initializer for <error> |
6767
| file://:0:0:0:0 | inline |
6868
| file://:0:0:0:0 | int |
69+
| file://:0:0:0:0 | is_consteval |
6970
| file://:0:0:0:0 | is_constexpr |
7071
| file://:0:0:0:0 | is_thread_local |
7172
| file://:0:0:0:0 | long |

cpp/ql/test/library-tests/templates/instantiations_functions/elements.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
| file://:0:0:0:0 | int |
111111
| file://:0:0:0:0 | int & |
112112
| file://:0:0:0:0 | int * |
113+
| file://:0:0:0:0 | is_consteval |
113114
| file://:0:0:0:0 | is_constexpr |
114115
| file://:0:0:0:0 | is_thread_local |
115116
| file://:0:0:0:0 | long |

cpp/ql/test/library-tests/unnamed/elements.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
| file://:0:0:0:0 | int | Other |
6060
| file://:0:0:0:0 | int * | Other |
6161
| file://:0:0:0:0 | int[0] | Other |
62+
| file://:0:0:0:0 | is_consteval | Other |
6263
| file://:0:0:0:0 | is_constexpr | Other |
6364
| file://:0:0:0:0 | is_thread_local | Other |
6465
| file://:0:0:0:0 | long | Other |

0 commit comments

Comments
 (0)