Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions cpp/ql/src/semmle/code/cpp/exprs/Lambda.qll
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LambdaExpression extends Expr, @lambdaexpr {
* Gets the nth implicitly or explicitly captured value of this lambda expression.
*/
LambdaCapture getCapture(int index) {
lambda_capture(result, underlyingElement(this), index, _, _, _)
lambda_capture(result, underlyingElement(this), index, _, _, _, _)
}

/**
Expand Down Expand Up @@ -64,7 +64,7 @@ class LambdaExpression extends Expr, @lambdaexpr {
* Gets the initializer that initializes the captured variables in the closure, if any.
* A lambda that does not capture any variables will not have an initializer.
*/
Expr getInitializer() {
ClassAggregateLiteral getInitializer() {
result = getChild(0)
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ class LambdaCapture extends @lambdacapture {
* Holds if this capture was made implicitly.
*/
predicate isImplicit() {
lambda_capture(this, _, _, _, true, _)
lambda_capture(this, _, _, _, _, true, _)
}

/**
Expand All @@ -122,7 +122,7 @@ class LambdaCapture extends @lambdacapture {
* is actually "*this" being captured rather than "this".]
*/
predicate isCapturedByReference() {
lambda_capture(this, _, _, true, _, _)
lambda_capture(this, _, _, _, true, _, _)
}

/**
Expand All @@ -134,16 +134,14 @@ class LambdaCapture extends @lambdacapture {
* expression which accesses the captured variable.
*/
Location getLocation() {
lambda_capture(this, _, _, _, _, result)
lambda_capture(this, _, _, _, _, _, result)
}

/**
* Gets the field of the lambda expression's closure type which is used to store this capture.
*/
MemberVariable getField() {
exists(LambdaExpression lambda, int index | this = lambda.getCapture(index) |
result = lambda.getType().(Closure).getCanonicalMember(index)
)
lambda_capture(this, _, _, result, _, _, _)
}

/**
Expand All @@ -154,9 +152,8 @@ class LambdaCapture extends @lambdacapture {
* For by-value captures of non-primitive types, this will be a call to a copy constructor.
*/
Expr getInitializer() {
exists(LambdaExpression lambda, int index | this = lambda.getCapture(index) |
result = lambda.getChild(0) // Call to the constructor of the closure type.
.getChild(index) // The appropriate argument to the constructor.
exists(LambdaExpression lambda | this = lambda.getCapture(_) |
result = lambda.getInitializer().getFieldExpr(this.getField())
)
}
}
1 change: 1 addition & 0 deletions cpp/ql/src/semmlecode.cpp.dbscheme
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,7 @@ lambda_capture(
unique int id: @lambdacapture,
int lambda: @lambdaexpr ref,
int index: int ref,
int field: @membervariable ref,
boolean captured_by_reference: boolean ref,
boolean is_implicit: boolean ref,
int location: @location_default ref
Expand Down
Loading