1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 506672 - Use ICPPEvaluation to evaluate all unary and binary C++ expressions

We were already using it for expressions whose operands didn't evaluate
to a number, but that missed expressions with enumeration operands (which
can call an overloaded operator).

Change-Id: I6f6e4ff3ba3c72db70ac6f8929473b065f2d758f
This commit is contained in:
Nathan Ridge 2016-11-26 02:31:09 -05:00
parent d48ebf5d25
commit 3a4f8c1ac7
2 changed files with 23 additions and 4 deletions

View file

@ -12051,6 +12051,17 @@ public class AST2CPPTests extends AST2TestBase {
parseAndCheckBindings();
}
// enum E { A = 2 };
// constexpr int operator+(E, E) {
// return 5;
// }
// constexpr int waldo = A + A;
public void testOverloadedOperatorWithEnumArgument_506672() throws Exception {
BindingAssertionHelper helper = getAssertionHelper();
helper.assertVariableValue("waldo", 5);
}
// class S {
// static S waldo;
// };

View file

@ -42,7 +42,6 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -55,7 +54,10 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment;
@ -264,6 +266,15 @@ public class ValueFactory {
* Computes the canonical representation of the value of the expression.
*/
private static IValue evaluate(IASTExpression exp) {
// Some C++ expression types can involve evaluating functions.
// For these, the value will be computed based on the evaluation.
if (exp instanceof ICPPASTFunctionCallExpression ||
exp instanceof ICPPASTSimpleTypeConstructorExpression ||
exp instanceof ICPPASTUnaryExpression ||
exp instanceof ICPPASTBinaryExpression) {
return null;
}
if (exp == null)
return IntegralValue.UNKNOWN;
@ -345,9 +356,6 @@ public class ValueFactory {
return null;
return applyBinaryTypeIdOperator(typeIdExp.getOperator(), t1, t2, exp);
}
if (exp instanceof IASTFunctionCallExpression || exp instanceof ICPPASTSimpleTypeConstructorExpression) {
return null; // The value will be obtained from the evaluation.
}
return IntegralValue.UNKNOWN;
}