mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Correct parsing of typeof-expressions, bug 226492.
This commit is contained in:
parent
1e97408e2b
commit
b74edd50a1
2 changed files with 16 additions and 7 deletions
|
@ -4478,6 +4478,15 @@ public class AST2Tests extends AST2BaseTest {
|
|||
// void test(int count) {
|
||||
// __typeof__(count) a= 1;
|
||||
// int ret0 = ((__typeof__(count)) 1);
|
||||
// }
|
||||
public void testTypeofUnaryExpression_Bug226492() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
parseAndCheckBindings(code, ParserLanguage.C, true);
|
||||
parseAndCheckBindings(code, ParserLanguage.CPP, true);
|
||||
}
|
||||
|
||||
// void test(int count) {
|
||||
// typeof(count==1) a= 1;
|
||||
// }
|
||||
public void testTypeofExpression_Bug226492() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
|
|
|
@ -850,15 +850,15 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
BacktrackException {
|
||||
int offset = consume().getOffset(); // t_typeof
|
||||
IASTTypeId d = null;
|
||||
IASTExpression unaryExpression = null;
|
||||
IASTExpression expression = null;
|
||||
|
||||
int lastOffset = 0;
|
||||
// prefer unary expressions over type-expressions
|
||||
// prefer expressions over type-ids
|
||||
if (LT(1) == IToken.tLPAREN && LT(2) != IToken.tLBRACE) {
|
||||
consume();
|
||||
final IToken m = mark();
|
||||
try {
|
||||
unaryExpression= unaryExpression();
|
||||
expression= expression();
|
||||
}
|
||||
catch (BacktrackException e) {
|
||||
backup(m);
|
||||
|
@ -868,14 +868,14 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||
} else {
|
||||
unaryExpression = unaryExpression();
|
||||
lastOffset = calculateEndOffset(unaryExpression);
|
||||
expression = unaryExpression();
|
||||
lastOffset = calculateEndOffset(expression);
|
||||
}
|
||||
if (d != null)
|
||||
return buildTypeIdExpression(IGNUASTTypeIdExpression.op_typeof, d, offset, lastOffset);
|
||||
|
||||
if (unaryExpression != null)
|
||||
return buildUnaryExpression(IGNUASTUnaryExpression.op_typeof, unaryExpression, offset, lastOffset);
|
||||
if (expression != null)
|
||||
return buildUnaryExpression(IGNUASTUnaryExpression.op_typeof, expression, offset, lastOffset);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue