diff --git a/cpp/ql/lib/semmle/code/cpp/Element.qll b/cpp/ql/lib/semmle/code/cpp/Element.qll index b30503d2c94..ffc0ede4daf 100644 --- a/cpp/ql/lib/semmle/code/cpp/Element.qll +++ b/cpp/ql/lib/semmle/code/cpp/Element.qll @@ -192,6 +192,11 @@ class Element extends ElementBase { */ predicate isAffectedByMacro() { affectedByMacro(this) } + /** Holds if this element is affected by the expansion of `mi`. */ + predicate isAffectedByMacro(MacroInvocation mi) { + affectedbymacroexpansion(underlyingElement(this), unresolveElement(mi)) + } + private Element getEnclosingElementPref() { enclosingfunction(underlyingElement(this), unresolveElement(result)) or result.(Function) = stmtEnclosingElement(this) or diff --git a/cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll b/cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll index 60e2635f338..851d987b1fd 100644 --- a/cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll +++ b/cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll @@ -23,7 +23,7 @@ class Expr extends StmtParent, @expr { predicate hasChild(Expr e, int n) { e = this.getChild(n) } /** Gets the enclosing function of this expression, if any. */ - Function getEnclosingFunction() { result = exprEnclosingElement(this) } + override Function getEnclosingFunction() { result = exprEnclosingElement(this) } /** Gets the nearest enclosing set of curly braces around this expression in the source, if any. */ BlockStmt getEnclosingBlock() { result = this.getEnclosingStmt().getEnclosingBlock() } diff --git a/cpp/ql/lib/semmle/code/cpp/stmts/Stmt.qll b/cpp/ql/lib/semmle/code/cpp/stmts/Stmt.qll index bd3a54c6159..cd750461244 100644 --- a/cpp/ql/lib/semmle/code/cpp/stmts/Stmt.qll +++ b/cpp/ql/lib/semmle/code/cpp/stmts/Stmt.qll @@ -20,7 +20,7 @@ class Stmt extends StmtParent, @stmt { predicate hasChild(Element e, int n) { this.getChild(n) = e } /** Gets the enclosing function of this statement, if any. */ - Function getEnclosingFunction() { result = stmtEnclosingElement(this) } + override Function getEnclosingFunction() { result = stmtEnclosingElement(this) } /** * Gets the nearest enclosing block of this statement in the source, if any. @@ -159,7 +159,10 @@ private class TStmtParent = @stmt or @expr; * * This is normally a statement, but may be a `StmtExpr`. */ -class StmtParent extends ControlFlowNode, TStmtParent { } +class StmtParent extends ControlFlowNode, TStmtParent { + /** Gets the enclosing function of this element, if any. */ + Function getEnclosingFunction() { none() } +} /** * A C/C++ 'expression' statement.