mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +02:00
[278797] CASTIdExpression getExpressionType() doesn't support enumerations
This commit is contained in:
parent
e9154e34f0
commit
06841d9793
2 changed files with 22 additions and 0 deletions
|
@ -6300,4 +6300,18 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertTrue(e instanceof IASTLiteralExpression);
|
||||
}
|
||||
|
||||
// enum myenum { value1, value2, value3 };
|
||||
//
|
||||
// void test() {
|
||||
// (int) value1;
|
||||
// }
|
||||
public void testBug278797() throws Exception {
|
||||
IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C);
|
||||
IASTFunctionDefinition func = (IASTFunctionDefinition)tu.getDeclarations()[1];
|
||||
IASTExpressionStatement stmt = ((IASTExpressionStatement)((IASTCompoundStatement)func.getBody()).getStatements()[0]);
|
||||
IType t = ((IASTCastExpression)stmt.getExpression()).getOperand().getExpressionType();
|
||||
assertNotNull(t);
|
||||
assertTrue(t instanceof IEnumeration);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,9 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
@ -97,6 +99,12 @@ public class CASTIdExpression extends ASTNode implements IASTIdExpression, IASTC
|
|||
if (binding instanceof IFunction) {
|
||||
return ((IFunction)binding).getType();
|
||||
}
|
||||
if (binding instanceof IEnumerator) {
|
||||
return ((IEnumerator)binding).getType();
|
||||
}
|
||||
if (binding instanceof IProblemBinding) {
|
||||
return (IProblemBinding)binding;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
return e.getProblem();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue