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 60e5a0bfbee..ef4211a2ee3 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 @@ -7569,4 +7569,16 @@ public class AST2Tests extends AST2TestBase { public void testAlignas_451082() throws Exception { parseAndCheckBindings(getAboveComment(), C); } + + // void foo(int waldo) { + // (waldo = 5) && waldo; + // } + public void testTypeIdWithEqualsInitializer_484824() throws Exception { + // Test that 'waldo = 5' is not parsed as a type-id, causing + // the entire expression to be parsed as a cast-expression. + // See also bug 471174, which is about the broader problem of + // binary && expressions with a parenthesized left operand + // being incorrectly parsed as cast-expressions. + parseAndCheckBindings(getAboveComment(), C); + } } 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 4e794266027..bc5eeef9edc 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 @@ -144,7 +144,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { @Override protected IASTInitializer optionalInitializer(IASTDeclarator dtor, DeclarationOptions options) throws EndOfFileException, BacktrackException { - if (LTcatchEOF(1) == IToken.tASSIGN) { + if (options.fAllowInitializer && LTcatchEOF(1) == IToken.tASSIGN) { final int offset= consume().getOffset(); IASTInitializerClause initClause = initClause(); IASTEqualsInitializer result= getNodeFactory().newEqualsInitializer(initClause);