mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-15 13:05:22 +02:00
Bug 479638 - Cache the result of EvalBinding.isConstantExpression()
This helps avoid infinite recursion when a variable's initializer references itself. Change-Id: I4667536ebbefd2008afe9003617092a0a5693db0 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
56635a1b57
commit
5cd555717b
2 changed files with 22 additions and 2 deletions
|
@ -417,7 +417,17 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// }
|
// }
|
||||||
public void testSelfReferencingVariable_452325() throws Exception {
|
public void testSelfReferencingVariable_452325() throws Exception {
|
||||||
// Just check that codan runs without any exceptions being thrown.
|
// Just check that codan runs without any exceptions being thrown.
|
||||||
checkSampleAbove();
|
checkSampleAboveCpp();
|
||||||
|
}
|
||||||
|
|
||||||
|
// int bar(int x) { return x; }
|
||||||
|
// int foo() { // error
|
||||||
|
// int waldo = bar(waldo);
|
||||||
|
// if (bar(waldo));
|
||||||
|
// }
|
||||||
|
public void testSelfReferencingVariable_479638() throws Exception {
|
||||||
|
// Just check that codan runs without any exceptions being thrown.
|
||||||
|
checkSampleAboveCpp();
|
||||||
}
|
}
|
||||||
|
|
||||||
// int foo(int x) { // error
|
// int foo(int x) { // error
|
||||||
|
|
|
@ -70,8 +70,10 @@ public class EvalBinding extends CPPDependentEvaluation {
|
||||||
private IType fType;
|
private IType fType;
|
||||||
private boolean fCheckedIsValueDependent;
|
private boolean fCheckedIsValueDependent;
|
||||||
private boolean fIsValueDependent;
|
private boolean fIsValueDependent;
|
||||||
private boolean fIsTypeDependent;
|
|
||||||
private boolean fCheckedIsTypeDependent;
|
private boolean fCheckedIsTypeDependent;
|
||||||
|
private boolean fIsTypeDependent;
|
||||||
|
private boolean fCheckedIsConstantExpression;
|
||||||
|
private boolean fIsConstantExpression;
|
||||||
|
|
||||||
public EvalBinding(IBinding binding, IType type, IASTNode pointOfDefinition) {
|
public EvalBinding(IBinding binding, IType type, IASTNode pointOfDefinition) {
|
||||||
this(binding, type, findEnclosingTemplate(pointOfDefinition));
|
this(binding, type, findEnclosingTemplate(pointOfDefinition));
|
||||||
|
@ -240,6 +242,14 @@ public class EvalBinding extends CPPDependentEvaluation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConstantExpression(IASTNode point) {
|
public boolean isConstantExpression(IASTNode point) {
|
||||||
|
if (!fCheckedIsConstantExpression) {
|
||||||
|
fCheckedIsConstantExpression = true;
|
||||||
|
fIsConstantExpression = computeIsConstantExpression(point);
|
||||||
|
}
|
||||||
|
return fIsConstantExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean computeIsConstantExpression(IASTNode point) {
|
||||||
return fBinding instanceof IEnumerator
|
return fBinding instanceof IEnumerator
|
||||||
|| fBinding instanceof ICPPFunction
|
|| fBinding instanceof ICPPFunction
|
||||||
|| (fBinding instanceof IVariable && isConstexprValue(((IVariable) fBinding).getInitialValue(), point));
|
|| (fBinding instanceof IVariable && isConstexprValue(((IVariable) fBinding).getInitialValue(), point));
|
||||||
|
|
Loading…
Add table
Reference in a new issue