mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
bug 84610 : Unnamed namespaces
This commit is contained in:
parent
b0f858c25b
commit
34ee61a5f8
2 changed files with 48 additions and 5 deletions
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue