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 11d9dbb76a4..71586ca951d 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 @@ -7302,4 +7302,23 @@ public class AST2Tests extends AST2BaseTest { td= bh.assertNonProblem("size_t", 0); assertEquals("unsigned long int", ASTTypeUtil.getType(td.getType())); } + + // void f(int a) { + // int tmp = a; + // } + // void f(int); + public void testParameterResolution() throws Exception { + final String code = getAboveComment(); + + BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + bh.assertNonProblem("f(int a)", 1); + bh.assertNonProblem("f(int)", 1); + bh.assertNonProblem("a;", 1); + + bh= new BindingAssertionHelper(code, false); + bh.assertNonProblem("f(int a)", 1); + bh.assertNonProblem("f(int)", 1); + bh.assertNonProblem("a;", 1); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java index f85a8d97da3..99c33bfb6e0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java @@ -84,11 +84,10 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI if (!(node instanceof IASTName)) return; IASTName name = (IASTName) node; - if (fDeclarations == null) { + if (fDeclarations == null || fDeclarations.length == 0) { fDeclarations = new IASTName[] { name }; } else { - //keep the lowest offset declaration in[0] - if (fDeclarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)fDeclarations[0]).getOffset()) { + if (isDeclaredBefore((ASTNode)node, (ASTNode)fDeclarations[0])) { fDeclarations = (IASTName[]) ArrayUtil.prepend(IASTName.class, fDeclarations, name); } else { fDeclarations = (IASTName[]) ArrayUtil.append(IASTName.class, fDeclarations, name); @@ -96,6 +95,14 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI } } + private boolean isDeclaredBefore(ASTNode n1, ASTNode n2) { + if (n1.getLength() == 0) + return false; + if (n2.getLength() == 0) + return true; + return n1.getOffset() < n2.getOffset(); + } + private IASTName getPrimaryDeclaration() { if (fDeclarations != null) { for (int i = 0; i < fDeclarations.length && fDeclarations[i] != null; i++) {