From 06d5c452ce549f9b5d0f130e2a3f045b6617d818 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 8 Oct 2014 14:57:36 -0700 Subject: [PATCH] Bug 446380 - Problem with int(expression) in enumerator value --- .../core/parser/tests/ast2/AST2CPPTests.java | 39 ++++++++++++++++--- .../cdt/internal/core/dom/parser/Value.java | 5 ++- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 97c08e21e07..44a5cfbf31c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -7607,16 +7607,45 @@ public class AST2CPPTests extends AST2TestBase { 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 { BindingAssertionHelper ba= getAssertionHelper(); ba.assertProblem("enum_name", 9); } - // struct MyStruct { - // enum MyEnum {}; - // MyStruct(MyEnum value) {} - // }; + // struct MyStruct { + // enum MyEnum {}; + // MyStruct(MyEnum value) {} + // }; public void testEnumRedefinitionInStruct_385144() throws Exception { parseAndCheckBindings(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java index 744ac6051dd..98d4156aead 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * 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.IVariable; 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.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; @@ -531,7 +532,7 @@ public class Value implements IValue { return null; 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 VALUE_CANNOT_BE_DETERMINED;