Skip to content

Commit 4ffbc2d

Browse files
committed
C++: Ensure we use lvalue reference types for structured bindings
This also adds a test for rvalue reference uses in the tuple structured binding case.
1 parent 074577b commit 4ffbc2d

File tree

6 files changed

+1118
-164
lines changed

6 files changed

+1118
-164
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ class TranslatedStructuredBindingVariableAccess extends TranslatedNonConstantExp
903903
}
904904

905905
private Type getReferenceType() {
906-
result.(ReferenceType).getBaseType() = expr.getUnderlyingType()
906+
result.(LValueReferenceType).getBaseType() = expr.getUnderlyingType()
907907
}
908908

909909
override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {

cpp/ql/lib/semmle/code/cpp/ir/internal/IRUtilities.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Type getVariableType(Variable v) {
4141
not exists(v.getInitializer()) and result = v.getType()
4242
else
4343
if isNonReferenceStructuredBinding(v)
44-
then exists(ReferenceType r | r.getBaseType() = v.getUnderlyingType() | result = r)
44+
then exists(LValueReferenceType r | r.getBaseType() = v.getUnderlyingType() | result = r)
4545
else result = v.getType()
4646
)
4747
}

0 commit comments

Comments
 (0)