diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java index bc2aab7d1fe..c0cec4cdf49 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java @@ -1272,4 +1272,15 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde assertEquals(hfile.getLocation().toOSString(), location.getFileName()); assertEquals(hoffset, location.getNodeOffset()); } + + // int waldo(int a, decltype(a) b); + public void testFunctionParameterReferencingPreviousParameter_432703() throws Exception { + String code = getAboveComment(); + IFile file = importFile("test.cpp", code); + waitUntilFileIsIndexed(index, file); + + int offset= code.indexOf("a)"); + IASTNode def = testF3(file, offset + 1); + assertTrue(def instanceof IASTName); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java index f7faf7fa1c7..2cca0472454 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java @@ -40,7 +40,9 @@ import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.ASTNameCollector; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter; import org.eclipse.cdt.core.dom.ast.IASTImplicitName; @@ -50,6 +52,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IParameter; @@ -407,14 +410,25 @@ class OpenDeclarationsJob extends Job implements ASTRunnable { private static boolean isInSameFunction(IASTName refName, IName funcDeclName) { if (funcDeclName instanceof IASTName) { - IASTDeclaration fdef = getEnclosingFunctionDefinition((IASTNode) funcDeclName); - return fdef != null && fdef.contains(refName); + IASTDeclaration fdecl = getEnclosingFunctionDeclaration((IASTNode) funcDeclName); + return fdecl != null && fdecl.contains(refName); } return false; } - private static IASTDeclaration getEnclosingFunctionDefinition(IASTNode node) { - while (node != null && !(node instanceof IASTFunctionDefinition)) { + private static boolean isFunctionDeclaration(IASTNode node) { + if (node instanceof IASTFunctionDefinition) { + return true; + } + if (node instanceof IASTSimpleDeclaration) { + IASTDeclarator[] declarators = ((IASTSimpleDeclaration) node).getDeclarators(); + return declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator; + } + return false; + } + + private static IASTDeclaration getEnclosingFunctionDeclaration(IASTNode node) { + while (node != null && !isFunctionDeclaration(node)) { node= node.getParent(); } return (IASTDeclaration) node;