From 005d40d228c7b88ccc935a24cbd35fa549a1abb4 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Sat, 18 Jul 2015 01:28:00 -0400 Subject: [PATCH] Bug 472950 - Account for the possibility of statements inside expressions in some of the parser's heuristic checks Change-Id: Ia91a00b91e0050838e990d1daad81b524816f8d0 Signed-off-by: Nathan Ridge --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 9 +++++++++ .../dom/parser/AbstractGNUSourceCodeParser.java | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index a964886ff26..60e5a0bfbee 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -4662,6 +4662,15 @@ public class AST2Tests extends AST2TestBase { parseAndCheckBindings(code, CPP, true); } + // int main() { + // (typeof(({ 0; }))) 0; + // } + public void testTypeofStatementExpressionInCastExpression_427950() throws Exception { + final String code = getAboveComment(); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); + } + // void test(int count) { // __typeof__(count) a= 1; // int ret0 = ((__typeof__(count)) 1); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index a8a4d1a9193..c8b85da97ee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -2664,9 +2664,23 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected void skipBrackets(int left, int right, int terminator) throws EndOfFileException, BacktrackException { consume(left); - int nesting= 0; + int nesting = 0; + int braceNesting = 0; while (true) { final int lt1= LT(1); + + // Ignore passages inside braces (such as for a statement-expression), + // as they can basically contain tokens of any kind. + if (lt1 == IToken.tLBRACE) { + braceNesting++; + } else if (lt1 == IToken.tRBRACE) { + braceNesting--; + } + if (braceNesting > 0) { + consume(); + continue; + } + if (lt1 == IToken.tEOC || lt1 == terminator) throwBacktrack(LA(1));