mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 514363 - Fix constexpr evaluation of assignment into array element
The computation had a bug where the array decayed to a pointer, and we tried to use the pointer's value as a composite value, instead of the underlying array's value. Change-Id: I9510d28e04deb0b8ef835e2857f8b513d11d1d72
This commit is contained in:
parent
301de3d40e
commit
f1f9ddf0f7
2 changed files with 26 additions and 1 deletions
|
@ -3140,4 +3140,17 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
public void testRegression_516338() throws Exception {
|
public void testRegression_516338() throws Exception {
|
||||||
checkBindings();
|
checkBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct Foo {
|
||||||
|
// char value[1];
|
||||||
|
// constexpr Foo() : value{0} {
|
||||||
|
// value[0] = 0; // Indexer fails here.
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
// constexpr auto foo = Foo{};
|
||||||
|
|
||||||
|
// // empty file
|
||||||
|
public void testAssignmentToMemberArrayElement_514363() throws Exception {
|
||||||
|
checkBindings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -491,7 +491,19 @@ public class EvalBinary extends CPPDependentEvaluation {
|
||||||
Number numericValue = fixed2.getValue().numberValue();
|
Number numericValue = fixed2.getValue().numberValue();
|
||||||
if (numericValue == null)
|
if (numericValue == null)
|
||||||
return EvalFixed.INCOMPLETE;
|
return EvalFixed.INCOMPLETE;
|
||||||
return new EvalCompositeAccess(fixed1, numericValue.intValue());
|
ICPPEvaluation composite = fixed1;
|
||||||
|
int arrayIndex = numericValue.intValue();
|
||||||
|
if (fixed1 instanceof EvalPointer) {
|
||||||
|
ICPPEvaluation elementEval = ((EvalPointer) fixed1).getTargetEvaluation();
|
||||||
|
if (elementEval instanceof EvalCompositeAccess) {
|
||||||
|
// 'composite' will now be the underlying array that the pointer points into.
|
||||||
|
// Since the pointer may not point at the beginning of the array, the array
|
||||||
|
// index needs to be shifted by the pointer's position.
|
||||||
|
composite = ((EvalCompositeAccess) elementEval).getParent();
|
||||||
|
arrayIndex += ((EvalPointer) fixed1).getPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new EvalCompositeAccess(composite, arrayIndex);
|
||||||
} else if ((isArray(fixed1) || isArray(fixed2)) && (hasIntType(fixed1) || hasIntType(fixed2))) {
|
} else if ((isArray(fixed1) || isArray(fixed2)) && (hasIntType(fixed1) || hasIntType(fixed2))) {
|
||||||
int offset = hasIntType(fixed1) ? fixed1.getValue().numberValue().intValue() : fixed2.getValue().numberValue().intValue();
|
int offset = hasIntType(fixed1) ? fixed1.getValue().numberValue().intValue() : fixed2.getValue().numberValue().intValue();
|
||||||
EvalCompositeAccess evalCompositeAccess = new EvalCompositeAccess(isArray(fixed1) ? fixed1 : fixed2, offset);
|
EvalCompositeAccess evalCompositeAccess = new EvalCompositeAccess(isArray(fixed1) ? fixed1 : fixed2, offset);
|
||||||
|
|
Loading…
Add table
Reference in a new issue