diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index dae978d5246..0675a6b454b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -1159,16 +1159,35 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals( name.getNames()[2].toString(), "ghi" ); //$NON-NLS-1$ } - public void _test84679() throws Exception { + public void testBug84679() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append("namespace Y { void f(float); } // NPE on resolve binding \n"); //$NON-NLS-1$ - buffer.append("namespace A { using namespace Y; f(int); } // NPE on resolve binding \n" ); //$NON-NLS-1$ - buffer.append("namespace B { void f(char); } // NPE on resolve binding \n "); //$NON-NLS-1$ - buffer.append("namespace AB { using namespace A; using namespace B; } \n" ); //$NON-NLS-1$ + buffer.append("namespace Y { void f(float); } \n"); //$NON-NLS-1$ + buffer.append("namespace A { using namespace Y; f(int); } \n"); //$NON-NLS-1$ + buffer.append("namespace B { void f(char); } \n"); //$NON-NLS-1$ + buffer.append("namespace AB { using namespace A; using namespace B; } \n"); //$NON-NLS-1$ buffer.append("void h(){ \n"); //$NON-NLS-1$ buffer.append(" AB::f(1); \n"); //$NON-NLS-1$ buffer.append(" AB::f(’c’); \n"); //$NON-NLS-1$ buffer.append("} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); + CPPNameCollector col = new CPPNameCollector(); + CPPVisitor.visitTranslationUnit(tu, col); + + ICPPNamespace Y = (ICPPNamespace) col.getName(0).resolveBinding(); + ICPPNamespace A = (ICPPNamespace) col.getName(3).resolveBinding(); + ICPPNamespace B = (ICPPNamespace) col.getName(7).resolveBinding(); + ICPPNamespace AB = (ICPPNamespace) col.getName(10).resolveBinding(); + + IFunction f = (IFunction) col.getName(16).resolveBinding(); + IFunction fdef = (IFunction) col.getName(5).resolveBinding(); + IProblemBinding f2 = (IProblemBinding) col.getName(19).resolveBinding(); + assertSame( f, fdef ); + assertEquals( IProblemBinding.SEMANTIC_NAME_NOT_FOUND, f2.getID() ); + assertInstances( col, Y, 2 ); + assertInstances( col, A, 2 ); + assertInstances( col, B, 2 ); + assertInstances( col, AB, 3 ); } public void testBug84692() throws Exception { @@ -1195,5 +1214,23 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances( col, Data, 2 ); } + public void testBug84686() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("namespace B { int b; } \n"); //$NON-NLS-1$ + buffer.append("namespace A { using namespace B; int a; } \n"); //$NON-NLS-1$ + buffer.append("namespace B { using namespace A; } \n"); //$NON-NLS-1$ + buffer.append("void f() { B::a++; } \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); + CPPNameCollector col = new CPPNameCollector(); + CPPVisitor.visitTranslationUnit(tu, col); + + assertEquals(col.size(), 11); + + IVariable a1 = (IVariable) col.getName(4).resolveBinding(); + IVariable a2 = (IVariable) col.getName(10).resolveBinding(); + assertSame( a1, a2 ); + } + } 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 fa6475b8045..f367b3dd56f 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 @@ -76,6 +76,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPCompositeBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; 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.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; @@ -457,7 +458,7 @@ public class CPPSemantics { ICPPScope scope = getLookupScope( name ); while( scope != null ){ IASTNode blockItem = CPPVisitor.getContainingBlockItem( node ); - if( scope.getPhysicalNode() != blockItem.getParent() ) + if( scope.getPhysicalNode() != blockItem.getParent() && !(scope instanceof ICPPNamespaceScope) ) blockItem = node; List directives = null; @@ -703,7 +704,7 @@ public class CPPSemantics { namespaceDefs = namespace.getNamespaceDefinitions(); nodes = ((ICPPASTNamespaceDefinition)namespaceDefs[0].getParent()).getDeclarations(); - namespaceIdx = -1; + namespaceIdx = 0; } else if( parent instanceof ICPPASTFunctionDeclarator ){ ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent; nodes = dtor.getParameters(); @@ -740,7 +741,7 @@ public class CPPSemantics { if( namespaceIdx > -1 ) { //check all definitions of this namespace while( namespaceIdx > -1 && namespaceDefs.length > ++namespaceIdx ){ - nodes = ((ICPPASTNamespaceDefinition)namespaceDefs[0].getParent()).getDeclarations(); + nodes = ((ICPPASTNamespaceDefinition)namespaceDefs[namespaceIdx].getParent()).getDeclarations(); if( nodes.length > 0 ){ idx = 0; item = nodes[0]; @@ -995,7 +996,7 @@ public class CPPSemantics { } else { if( obj == null ) obj = temp; - else { + else if( obj != temp ){ return new ProblemBinding( IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name ); } } @@ -1200,6 +1201,8 @@ public class CPPSemantics { for( int j = 0; j < numSourceParams || j == 0; j++ ){ source = getSourceParameterType( sourceParameters, j ); + if( source instanceof IProblemBinding ) + return (IBinding) source; if( j < numTargetParams ){ if( targetLength == 0 && j == 0 ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index 2a55c58496c..2c16005e809 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -1569,6 +1569,8 @@ public class CPPVisitor { } catch ( DOMException e ) { return e.getProblem(); } + } else if( binding instanceof IProblemBinding ){ + return (IType) binding; } } else if( expression instanceof IASTCastExpression ){ IASTTypeId id = ((IASTCastExpression)expression).getTypeId();