Skip to content

Commit c7b6681

Browse files
authored
Merge pull request github#3929 from igfoo/static_assert
C++: Give static assertions an enclosing element
2 parents 7dd2677 + 616bad7 commit c7b6681

File tree

7 files changed

+6039
-1521
lines changed

7 files changed

+6039
-1521
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ class Element extends ElementBase {
197197
initialisers(underlyingElement(this), unresolveElement(result), _, _) or
198198
exprconv(unresolveElement(result), underlyingElement(this)) or
199199
param_decl_bind(underlyingElement(this), _, unresolveElement(result)) or
200-
using_container(unresolveElement(result), underlyingElement(this))
200+
using_container(unresolveElement(result), underlyingElement(this)) or
201+
static_asserts(unresolveElement(this), _, _, _, underlyingElement(result))
201202
}
202203

203204
/** Gets the closest `Element` enclosing this one. */
@@ -278,12 +279,12 @@ class StaticAssert extends Locatable, @static_assert {
278279
/**
279280
* Gets the expression which this static assertion ensures is true.
280281
*/
281-
Expr getCondition() { static_asserts(underlyingElement(this), unresolveElement(result), _, _) }
282+
Expr getCondition() { static_asserts(underlyingElement(this), unresolveElement(result), _, _, _) }
282283

283284
/**
284285
* Gets the message which will be reported by the compiler if this static assertion fails.
285286
*/
286-
string getMessage() { static_asserts(underlyingElement(this), _, result, _) }
287+
string getMessage() { static_asserts(underlyingElement(this), _, result, _, _) }
287288

288-
override Location getLocation() { static_asserts(underlyingElement(this), _, _, result) }
289+
override Location getLocation() { static_asserts(underlyingElement(this), _, _, result, _) }
289290
}

cpp/ql/src/semmlecode.cpp.dbscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ static_asserts(
508508
unique int id: @static_assert,
509509
int condition : @expr ref,
510510
string message : string ref,
511-
int location: @location_default ref
511+
int location: @location_default ref,
512+
int enclosing : @element ref
512513
);
513514

514515
// each function has an ordered list of parameters

0 commit comments

Comments
 (0)