1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 19:35:36 +02:00

Bug 486140 - Cast expression with label reference expression as operand

Change-Id: I77d8e7dabc64f68818f4222ffe3d6ba7eebae542
This commit is contained in:
Nathan Ridge 2017-10-15 00:42:42 -04:00
parent 20cebd8f6f
commit 4c1a6e0ccd
2 changed files with 37 additions and 1 deletions

View file

@ -7569,6 +7569,41 @@ public class AST2Tests extends AST2TestBase {
parseAndCheckBindings(true); parseAndCheckBindings(true);
} }
// void f() {
// unsigned long long labelPtr;
// labelPtr = (unsigned long long) &&L;
// goto *labelPtr;
// L:
// return;
// }
public void testExpressionLabelReferenceCast_486140a() throws Exception {
// Here, the cast-expression is the only valid parse.
parseAndCheckBindings(true);
}
// typedef unsigned long long ULL;
// void f() {
// unsigned long long labelPtr;
// labelPtr = (ULL) &&L;
// goto *labelPtr;
// L:
// return;
// }
public void testExpressionLabelReferenceCast_486140b() throws Exception {
// Here, the cast-expression and the binary-expression are both
// syntactically valid, but the correct parse is the cast-expression.
parseAndCheckBindings(true);
}
// int test(int waldo, int other) {
// return (waldo) && other;
// }
public void testBinaryExprNotMisparsedAsCast_486140() throws Exception {
// Again cast-expression and binary-expression are both syntactically
// valid, but this time the correct parse is binary-expression.
parseAndCheckBindings(true);
}
// int version = 0; // int version = 0;
// int NextVersion() { // int NextVersion() {
// return __atomic_add_fetch(&version, 1, 5); // return __atomic_add_fetch(&version, 1, 5);

View file

@ -1097,6 +1097,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
break; break;
case IToken.tAND: case IToken.tAND:
op= IASTBinaryExpression.op_logicalAnd; op= IASTBinaryExpression.op_logicalAnd;
unaryOp = IASTUnaryExpression.op_labelReference;
break; break;
case IToken.tBITOR: case IToken.tBITOR:
op= IASTBinaryExpression.op_binaryOr; op= IASTBinaryExpression.op_binaryOr;
@ -1269,6 +1270,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
// ambiguity with unary operator // ambiguity with unary operator
case IToken.tPLUS: case IToken.tMINUS: case IToken.tPLUS: case IToken.tMINUS:
case IToken.tSTAR: case IToken.tAMPER: case IToken.tSTAR: case IToken.tAMPER:
case IToken.tAND:
final int operatorOffset = LA(1).getOffset(); final int operatorOffset = LA(1).getOffset();
IToken markEnd= mark(); IToken markEnd= mark();
backup(mark); backup(mark);
@ -2597,7 +2599,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
skipBrackets(IToken.tLPAREN, IToken.tRPAREN, IToken.tSEMI); skipBrackets(IToken.tLPAREN, IToken.tRPAREN, IToken.tSEMI);
switch (LTcatchEOF(1)) { switch (LTcatchEOF(1)) {
case IToken.tAMPERASSIGN: case IToken.tAMPERASSIGN:
case IToken.tAND:
case IToken.tARROW: case IToken.tARROW:
case IToken.tARROWSTAR: case IToken.tARROWSTAR:
case IToken.tASSIGN: case IToken.tASSIGN: