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 6c5d5c89bcc..04e62edd2ce 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 @@ -1258,6 +1258,21 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti getBindingFromASTName("a= 1", 1); getBindingFromASTName("b= 1", 1); } + + // namespace x { + // int a(int); + // } + // using namespace x; + // using x::a; + + // #include "header.h" + // void test() { + // a(1); + // } + public void testLegalConflictWithUsingDeclaration() throws Exception { + getBindingFromASTName("a(1)", 1); + } + /* CPP assertion helpers */ /* ##################################################################### */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java index 1a7f5ea049d..e73099db925 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java @@ -21,8 +21,10 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.internal.core.index.IIndexScope; @@ -62,7 +64,7 @@ public class CPPScopeMapper { if (parent instanceof IIndexScope) { return mapToASTScope((IIndexScope) parent); } - return fTuScope; + return fTu.getScope(); } public IName getScopeName() throws DOMException { @@ -99,7 +101,7 @@ public class CPPScopeMapper { public IScope getContainingScope() { final IScope scope= fDirective.getContainingScope(); if (scope == null) { - return fTuScope; + return fTu.getScope(); } return scope; } @@ -118,11 +120,11 @@ public class CPPScopeMapper { private final HashMap fMappedScopes= new HashMap(); private final HashMap fNamespaceWrappers= new HashMap(); private final Map> fPerName= new HashMap>(); - private final CPPNamespaceScope fTuScope; + private final CPPASTTranslationUnit fTu; public CPPScopeMapper(CPPASTTranslationUnit tu) { - fTuScope= tu.getScope(); + fTu= tu; } /** @@ -169,13 +171,14 @@ public class CPPScopeMapper { } private String getReverseQualifiedName(IScope scope) throws DOMException { - if (scope == fTuScope || scope == null) { + final CPPNamespaceScope tuscope = fTu.getScope(); + if (scope == tuscope || scope == null) { return ""; //$NON-NLS-1$ } StringBuilder buf= new StringBuilder(); buf.append(scope.getScopeName().toCharArray()); scope= scope.getParent(); - while (scope != null && scope != fTuScope) { + while (scope != null && scope != tuscope) { buf.append(':'); buf.append(scope.getScopeName().toCharArray()); scope= scope.getParent(); @@ -188,14 +191,14 @@ public class CPPScopeMapper { */ public IScope mapToASTScope(IIndexScope scope) { if (scope == null) { - return fTuScope; + return fTu.getScope(); } if (scope instanceof ICPPNamespaceScope) { IScope result= fMappedScopes.get(scope); if (result == null) { - result= fTuScope.findNamespaceScope(scope); + result= fTu.getScope().findNamespaceScope(scope); if (result == null) { - result= wrapNamespaceScope(scope); + result= wrapNamespaceScope((ICPPNamespaceScope) scope); } fMappedScopes.put(scope, result); } @@ -204,12 +207,12 @@ public class CPPScopeMapper { return scope; } - private IScope wrapNamespaceScope(IIndexScope scope) { + private IScope wrapNamespaceScope(ICPPNamespaceScope scope) { try { String rqname= getReverseQualifiedName(scope); NamespaceScopeWrapper result= fNamespaceWrappers.get(rqname); if (result == null) { - result= new NamespaceScopeWrapper((ICPPNamespaceScope) scope); + result= new NamespaceScopeWrapper(getCompositeNamespaceScope(scope)); fNamespaceWrappers.put(rqname, result); } return result; @@ -218,4 +221,14 @@ public class CPPScopeMapper { return null; } } + + private ICPPNamespaceScope getCompositeNamespaceScope(ICPPNamespaceScope scope) throws DOMException { + if (scope instanceof IIndexScope) { + IIndexBinding binding= fTu.getIndex().adaptBinding(((IIndexScope) scope).getScopeBinding()); + if (binding instanceof ICPPNamespace) { + scope= ((ICPPNamespace) binding).getNamespaceScope(); + } + } + return scope; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index 70886dfe887..bda2979901a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -1074,7 +1074,7 @@ public class CPPSemantics { IBinding binding = scope.getBinding( data.astName, false, fileSet ); if (binding instanceof CPPImplicitFunction || binding instanceof CPPImplicitTypedef) mergeResults( data, binding, true ); - else + else if (binding != null) b = new IBinding[] { binding }; } else { b = scope.getBindings( data.astName, false, data.prefixLookup, fileSet ); @@ -2399,9 +2399,9 @@ public class CPPSemantics { outer: for( int fnIdx = 0; fnIdx < numFns; fnIdx++ ){ currFn = (IFunction) fns[fnIdx]; - if( currFn == null || bestFn == currFn || - ( bestFn instanceof ICPPDelegate && ((ICPPDelegate)bestFn).getBinding() == currFn ) || - ( currFn instanceof ICPPDelegate && ((ICPPDelegate)currFn).getBinding() == bestFn ) ) + if (currFn == null || bestFn == currFn || + (bestFn instanceof ICPPDelegate && currFn.equals(((ICPPDelegate)bestFn).getBinding())) || + (bestFn != null && currFn instanceof ICPPDelegate && bestFn.equals(((ICPPDelegate)currFn).getBinding())) ) { continue; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java index ecb9fcab41c..cb415e16ebf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java @@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexName; -import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.composite.CompositeScope; @@ -53,12 +52,13 @@ class CompositeCPPNamespaceScope extends CompositeScope implements ICPPNamespace public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException { - IBinding[] preresult = null; + IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][]; for(int i=0; i