From ae2d1154f9f0a3c4a379418c40f1c1ffb05c7488 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 6 May 2014 17:14:30 -0700 Subject: [PATCH] Bug 434150 - Infinite recursion with decltype --- .../tests/IndexCPPBindingResolutionTest.java | 14 +++++++++++- .../core/dom/parser/cpp/CPPVariable.java | 22 +++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java index 6b3d2c3cabf..940b0012d31 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Symbian Software Systems and others. + * Copyright (c) 2007, 2014 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -768,6 +768,18 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti assertQNEquals("n1::n2::Int", b12); } + // struct A { + // static struct { + // } waldo; + // }; + // decltype(A::waldo) A::waldo; + + // A a; + public void testDecltype_434150() throws Exception { + checkBindings(); + } + + // // header content // enum E { ER1, ER2 }; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java index 790a9fe652d..e5b084f6d58 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * Andrew Niefer (IBM Corporation) - Initial API and implementation * Markus Schorn (Wind River Systems) * Ed Swartz (Nokia) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -126,11 +127,24 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt if (fType != null) { return fType; } - + + boolean doneWithDefinition = false; IArrayType firstCandidate= null; final int length = fDeclarations == null ? 0 : fDeclarations.length; - for (int i = -1; i < length; i++) { - IASTName n = i == -1 ? fDefinition : fDeclarations[i]; + for (int i = 0; i <= length; i++) { + IASTName n; + // Process the definition according to its relative position among the declarations. + // See http://bugs.eclipse.org/434150 + if (fDefinition != null && !doneWithDefinition && + (i == length || ((ASTNode) fDefinition).getOffset() < ((ASTNode) fDeclarations[i]).getOffset())) { + n = fDefinition; + doneWithDefinition = true; + --i; // We still have to come back to the declaration at position i. + } else if (i < length) { + n = fDeclarations[i]; + } else { + break; + } if (n != null) { while (n.getParent() instanceof IASTName) n = (IASTName) n.getParent();