From 34ee61a5f87fa910b69bd72a305756b73c42ea02 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Fri, 11 Feb 2005 18:56:56 +0000 Subject: [PATCH] bug 84610 : Unnamed namespaces --- .../core/parser/tests/ast2/AST2CPPTests.java | 38 ++++++++++++++++++- .../core/dom/parser/cpp/CPPSemantics.java | 15 ++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) 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 d3662b4ca93..1b97331048a 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 @@ -1363,8 +1363,42 @@ public class AST2CPPTests extends AST2BaseTest { assertSame( f2, fref ); assertNotNull( f1 ); assertNotNull( f2 ); - - + } + + public void testBug84610() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("namespace { int i; } //1\n" ); //$NON-NLS-1$ + buffer.append("void f(){ i; } \n" ); //$NON-NLS-1$ + buffer.append("namespace A { \n" ); //$NON-NLS-1$ + buffer.append(" namespace { \n" ); //$NON-NLS-1$ + buffer.append(" int i; //2 \n" ); //$NON-NLS-1$ + buffer.append(" int j; \n" ); //$NON-NLS-1$ + buffer.append(" } \n" ); //$NON-NLS-1$ + buffer.append(" void g(){ i; } \n" ); //$NON-NLS-1$ + buffer.append("} \n" ); //$NON-NLS-1$ + buffer.append("using namespace A; \n" ); //$NON-NLS-1$ + buffer.append("void h() { \n" ); //$NON-NLS-1$ + buffer.append(" i; //ambiguous \n" ); //$NON-NLS-1$ + buffer.append(" A::i; //i2 \n" ); //$NON-NLS-1$ + buffer.append(" j; \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); + + assertEquals( 17, col.size() ); + + IVariable i1 = (IVariable) col.getName(1).resolveBinding(); + IVariable i2 = (IVariable) col.getName(6).resolveBinding(); + IVariable j = (IVariable) col.getName(7).resolveBinding(); + + assertInstances( col, i1, 2 ); + assertInstances( col, i2, 4 ); + assertInstances( col, j, 2 ); + + IProblemBinding problem = (IProblemBinding) col.getName(12).resolveBinding(); + assertEquals( IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, problem.getID() ); } } 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 9c416e31c4d..fcceb9fe8ce 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 @@ -704,8 +704,13 @@ public class CPPSemantics { int size = directives.size(); for( int i = 0; i < size; i++ ){ - IASTName qualName = ((ICPPASTUsingDirective)directives.get(i)).getQualifiedName(); - IBinding binding = qualName.resolveBinding(); + Object d = directives.get(i); + IBinding binding = null; + if( d instanceof ICPPASTUsingDirective ){ + binding = ((ICPPASTUsingDirective)d).getQualifiedName().resolveBinding(); + } else if( d instanceof ICPPASTNamespaceDefinition ){ + binding = ((ICPPASTNamespaceDefinition)d).getName().resolveBinding(); + } if( binding instanceof ICPPNamespace ){ temp = ((ICPPNamespace)binding).getNamespaceScope(); } else @@ -803,7 +808,11 @@ public class CPPSemantics { break; if( item != blockItem || data.includeBlockItem( item ) ){ - if( item instanceof ICPPASTUsingDirective && !data.ignoreUsingDirectives ) { + if( !data.ignoreUsingDirectives && + ( item instanceof ICPPASTUsingDirective || + (item instanceof ICPPASTNamespaceDefinition && + ((ICPPASTNamespaceDefinition)item).getName().toCharArray().length == 0) ) ) + { if( usingDirectives != null ) usingDirectives.add( item ); } else {