mirror of
https://github.com/github/codeql.git
synced 2026-05-05 21:55:19 +02:00
C++: Give names in structured binding declarations correct IR types
This commit is contained in:
@@ -11,6 +11,15 @@ private Type getDecayedType(Type type) {
|
||||
result.(PointerType).getBaseType() = type.(ArrayType).getBaseType()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if the sepcified variable is a structured binding with a non-reference
|
||||
* type.
|
||||
*/
|
||||
predicate isNonReferenceStructuredBinding(Variable v) {
|
||||
v.isStructuredBinding() and
|
||||
not v.getUnderlyingType() instanceof ReferenceType
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual type of the specified variable, as opposed to the declared type.
|
||||
* This returns the type of the variable after any pointer decay is applied, and
|
||||
@@ -30,7 +39,10 @@ Type getVariableType(Variable v) {
|
||||
result = v.getInitializer().getExpr().getType()
|
||||
or
|
||||
not exists(v.getInitializer()) and result = v.getType()
|
||||
else result = v.getType()
|
||||
else
|
||||
if isNonReferenceStructuredBinding(v)
|
||||
then exists(ReferenceType r | r.getBaseType() = v.getUnderlyingType() | result = r)
|
||||
else result = v.getType()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user