From e96d2f92c88742e5cb2c670accbb441429f0dc46 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Wed, 18 Oct 2017 21:27:15 -0400 Subject: [PATCH] Bug 526134 - Recover from failure to parse a base-clause in a class-specifier Change-Id: I642650020dc2c0363376c8172769f4b5ea2d90c4 --- .../eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java | 6 ++++++ .../internal/core/dom/parser/cpp/GNUCPPSourceParser.java | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 5813e8f400a..7edbc1e87a6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -12410,4 +12410,10 @@ public class AST2CPPTests extends AST2CPPTestBase { BindingAssertionHelper helper = getAssertionHelper(); helper.assertVariableValue("waldo", 1); } + + // struct A {}; + // struct A* b = (1 == 1) ? new struct A : new struct A; + public void test_ElabTypeSpecInNewExprInConditional_526134() throws Exception { + parseAndCheckBindings(); + } } 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 d4e6f8a9a1b..a2b01fec885 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 @@ -4768,7 +4768,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // base clause if (LT(1) == IToken.tCOLON) { - baseClause(astClassSpecifier); + try { + baseClause(astClassSpecifier); + } catch (BacktrackException e) { + // Couldn't parse a base-clause. + // Backtrack and try an elaborated-type-specifier instead. + backup(mark); + throw e; + } // content assist within the base-clause if (LT(1) == IToken.tEOC) { return astClassSpecifier;