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 d9db2e1e08c..cef0bece206 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 @@ -5297,6 +5297,14 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); } + // int foo = 42; + // typedef char StupidType; + // StupidType const *bar = (StupidType const*)&foo; + public void testUnusualDeclSpecOrdering_Bug251514() throws Exception { + parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); + parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); + } + // #define IF if // #define IF_P if ( // #define IF_P_T if (1 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index bfbe066a803..5dcf22cd4cd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation + * John Camelon (IBM Rational Software) - Initial API and implementation * Markus Schorn (Wind River Systems) * Ed Swartz (Nokia) * Mike Kucera (IBM) - bug #206952 @@ -837,9 +837,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { if (supportStatementsInExpressions && LT(2) == IToken.tLBRACE) { return compoundStatementExpression(); } - t = consume(); - // TODO - do we need to return a wrapper? IASTExpression lhs = expression(); int finalOffset = 0; switch (LT(1)) { @@ -850,9 +848,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { default: throwBacktrack(LA(1)); } - - return buildUnaryExpression( - IASTUnaryExpression.op_bracketedPrimary, lhs, t.getOffset(), finalOffset); + return buildUnaryExpression(IASTUnaryExpression.op_bracketedPrimary, lhs, t.getOffset(), finalOffset); case IToken.tIDENTIFIER: case IToken.tCOMPLETION: case IToken.tEOC: diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 4560187d2df..d9e6e33dca5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * John Camelon (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) * Bryan Wilkinson (QNX) - https://bugs.eclipse.org/bugs/show_bug.cgi?id=151207 * Ed Swartz (Nokia) @@ -164,8 +164,6 @@ import org.eclipse.cdt.internal.core.parser.token.TokenFactory; * This is our implementation of the IParser interface, serving as a parser for * GNU C and C++. From time to time we will make reference to the ANSI ISO * specifications. - * - * @author jcamelon */ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private static final int DEFAULT_PARM_LIST_SIZE = 4; @@ -1431,11 +1429,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { t = consume(); int finalOffset= 0; IASTExpression lhs= expression(); - if (LT(1) == IToken.tRPAREN) { - finalOffset = consume().getEndOffset(); - } else { - // missing parenthesis, assume it's there and keep going. - finalOffset = LA(1).getOffset(); + switch (LT(1)) { + case IToken.tRPAREN: + case IToken.tEOC: + finalOffset = consume().getEndOffset(); + break; + default: + throwBacktrack(LA(1)); } return buildUnaryExpression(IASTUnaryExpression.op_bracketedPrimary, lhs, t.getOffset(), finalOffset); case IToken.tIDENTIFIER: