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.
This commit is contained in:
Jeroen Ketema
2022-02-25 13:31:56 +01:00
parent 074577b539
commit 4ffbc2d148
6 changed files with 1118 additions and 164 deletions

View File

@@ -903,7 +903,7 @@ class TranslatedStructuredBindingVariableAccess extends TranslatedNonConstantExp
}
private Type getReferenceType() {
result.(ReferenceType).getBaseType() = expr.getUnderlyingType()
result.(LValueReferenceType).getBaseType() = expr.getUnderlyingType()
}
override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {

View File

@@ -41,7 +41,7 @@ Type getVariableType(Variable v) {
not exists(v.getInitializer()) and result = v.getType()
else
if isNonReferenceStructuredBinding(v)
then exists(ReferenceType r | r.getBaseType() = v.getUnderlyingType() | result = r)
then exists(LValueReferenceType r | r.getBaseType() = v.getUnderlyingType() | result = r)
else result = v.getType()
)
}