Skip to content

Commit 08bb794

Browse files
authored
Merge pull request github#17125 from jketema/explicit-bool
C++: Expose `explicit` and `explicit(bool)` function specifiers
2 parents 9794309 + 742922c commit 08bb794

File tree

12 files changed

+10881
-1568
lines changed

12 files changed

+10881
-1568
lines changed

cpp/downgrades/68930f3b81bbe3fdbb91c850deca1fec8072d62a/old.dbscheme

Lines changed: 2310 additions & 0 deletions
Large diffs are not rendered by default.

cpp/downgrades/68930f3b81bbe3fdbb91c850deca1fec8072d62a/semmlecode.cpp.dbscheme

Lines changed: 2305 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
description: description: Support explicit(bool) specifiers
2+
compatibility: full
3+
explicit_specifier_exprs.rel: delete
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: feature
3+
---
4+
* An `isExplicit` predicate was added to the `Function` class that determines whether the function was declared as explicit.
5+
* A `getExplicitExpr` predicate was added to the `Function` class that yields the constant boolean expression (if any) that conditionally determines whether the function is explicit.

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,26 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
158158
*/
159159
predicate isConsteval() { this.hasSpecifier("is_consteval") }
160160

161+
/**
162+
* Holds if this function is declared to be `explicit`.
163+
*/
164+
predicate isExplicit() { this.hasSpecifier("explicit") }
165+
166+
/**
167+
* Gets the constant expression that determines whether the function is explicit.
168+
*
169+
* For example, for the following code the result is the expression `sizeof(T) == 1`:
170+
* ```
171+
* template<typename T> struct C {
172+
* explicit(sizeof(T) == 1)
173+
* C(const T);
174+
* };
175+
* ```
176+
*/
177+
Expr getExplicitExpr() {
178+
explicit_specifier_exprs(underlyingElement(this), unresolveElement(result))
179+
}
180+
161181
/**
162182
* Holds if this function is declared with `__attribute__((naked))` or
163183
* `__declspec(naked)`.

cpp/ql/lib/semmlecode.cpp.dbscheme

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,11 @@ varspecifiers(
921921
int spec_id: @specifier ref
922922
);
923923

924+
explicit_specifier_exprs(
925+
unique int func_id: @function ref,
926+
int constant: @expr ref
927+
)
928+
924929
attributes(
925930
unique int id: @attribute,
926931
int kind: int ref,

0 commit comments

Comments
 (0)