From c21f219ab7e8eff57e34845db1020861526fc083 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Fri, 7 Dec 2012 12:29:07 -0800 Subject: [PATCH] Bug 395875 - Error involving dependent expression in index Change-Id: I2f50373220a02d5856fb88cf040c44de28fb5a79 Reviewed-on: https://git.eclipse.org/r/9064 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../tests/IndexCPPTemplateResolutionTest.java | 15 +++++++++++++++ .../core/dom/parser/cpp/semantics/CPPVisitor.java | 14 ++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java index 0e8fded9b54..57ffaefda0b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -9,6 +9,7 @@ * Andrew Ferguson (Symbian) - Initial implementation * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; @@ -2175,4 +2176,18 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa public void testLambdaExpression_395884() throws Exception { checkBindings(); } + + // template int bar(T); + // template struct S { + // template auto foo(T t) const -> decltype(bar(t)); + // }; + + // void f(int); + // void test() { + // S<1> n; + // f(n.foo(0)); + // } + public void testDependentExpression_395875() throws Exception { + getBindingFromASTName("f(n.foo(0))", 1, ICPPFunction.class); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index bb1138eb81a..7b634dc0f5d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -2434,13 +2434,19 @@ public class CPPVisitor extends ASTQueries { * Searches for the function enclosing the given node. May return null. */ public static IBinding findEnclosingFunction(IASTNode node) { - while (node != null && !(node instanceof IASTFunctionDefinition)) { + IASTDeclarator dtor = null; + while (node != null) { + if (node instanceof IASTFunctionDeclarator) { + dtor = (IASTDeclarator) node; + break; + } + if (node instanceof IASTFunctionDefinition) { + dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()); + break; + } node= node.getParent(); } - if (node == null) - return null; - IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()); if (dtor != null) { IASTName name= dtor.getName(); if (name != null) {