mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Bug 446380 - Problem with int(expression) in enumerator value
This commit is contained in:
parent
044d2cfaae
commit
06d5c452ce
2 changed files with 37 additions and 7 deletions
|
@ -7607,16 +7607,45 @@ public class AST2CPPTests extends AST2TestBase {
|
||||||
assertEquals(IBasicType.IS_LONG, ((ICPPBasicType) t3).getModifiers());
|
assertEquals(IBasicType.IS_LONG, ((ICPPBasicType) t3).getModifiers());
|
||||||
}
|
}
|
||||||
|
|
||||||
// typedef enum enum_name enum_name;
|
// void f(int t);
|
||||||
|
// void f(long t);
|
||||||
|
//
|
||||||
|
// enum e {
|
||||||
|
// i1 = 0L,
|
||||||
|
// i2 = (long) i1 + 1,
|
||||||
|
// i3 = long(i2 + 1)
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// void test() {
|
||||||
|
// f(i3);
|
||||||
|
// }
|
||||||
|
public void testCastInEnumeratorValue_446380() throws Exception {
|
||||||
|
BindingAssertionHelper ba= getAssertionHelper();
|
||||||
|
IEnumerator i2 = ba.assertNonProblem("i2", IEnumerator.class);
|
||||||
|
Long v2 = i2.getValue().numericalValue();
|
||||||
|
assertNotNull(v2);
|
||||||
|
assertEquals(1, v2.intValue());
|
||||||
|
IEnumerator i3 = ba.assertNonProblem("i3", IEnumerator.class);
|
||||||
|
Long v3 = i3.getValue().numericalValue();
|
||||||
|
assertNotNull(v3);
|
||||||
|
assertEquals(2, v3.intValue());
|
||||||
|
ICPPFunction f = ba.assertNonProblemOnFirstIdentifier("f(i3)",ICPPFunction.class);
|
||||||
|
IType t = f.getType().getParameterTypes()[0];
|
||||||
|
// The declared types of the enum values don't affect the underlying type of the enum,
|
||||||
|
// only the values themselves do.
|
||||||
|
assertEquals("int", ASTTypeUtil.getType(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
// typedef enum enum_name enum_name;
|
||||||
public void testTypedefRecursion_285457() throws Exception {
|
public void testTypedefRecursion_285457() throws Exception {
|
||||||
BindingAssertionHelper ba= getAssertionHelper();
|
BindingAssertionHelper ba= getAssertionHelper();
|
||||||
ba.assertProblem("enum_name", 9);
|
ba.assertProblem("enum_name", 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct MyStruct {
|
// struct MyStruct {
|
||||||
// enum MyEnum {};
|
// enum MyEnum {};
|
||||||
// MyStruct(MyEnum value) {}
|
// MyStruct(MyEnum value) {}
|
||||||
// };
|
// };
|
||||||
public void testEnumRedefinitionInStruct_385144() throws Exception {
|
public void testEnumRedefinitionInStruct_385144() throws Exception {
|
||||||
parseAndCheckBindings();
|
parseAndCheckBindings();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2012 Wind River Systems, Inc. and others.
|
* Copyright (c) 2008, 2014 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -56,6 +56,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||||
|
@ -531,7 +532,7 @@ public class Value implements IValue {
|
||||||
return null;
|
return null;
|
||||||
return applyBinaryTypeIdOperator(typeIdExp.getOperator(), t1, t2, exp);
|
return applyBinaryTypeIdOperator(typeIdExp.getOperator(), t1, t2, exp);
|
||||||
}
|
}
|
||||||
if (exp instanceof IASTFunctionCallExpression) {
|
if (exp instanceof IASTFunctionCallExpression || exp instanceof ICPPASTSimpleTypeConstructorExpression) {
|
||||||
return null; // The value will be obtained from the evaluation.
|
return null; // The value will be obtained from the evaluation.
|
||||||
}
|
}
|
||||||
return VALUE_CANNOT_BE_DETERMINED;
|
return VALUE_CANNOT_BE_DETERMINED;
|
||||||
|
|
Loading…
Add table
Reference in a new issue