1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

fix bug 86319

This commit is contained in:
Andrew Niefer 2005-02-23 22:34:47 +00:00
parent 3b61a8117e
commit 7b8ec083f0
2 changed files with 24 additions and 0 deletions

View file

@ -2142,5 +2142,27 @@ public class AST2CPPTests extends AST2BaseTest {
CPPNameCollector col = new CPPNameCollector();
tu.getVisitor().visitTranslationUnit(col);
}
public void testBug86319() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("void foo() { \n"); //$NON-NLS-1$
buffer.append(" int i = 42; \n"); //$NON-NLS-1$
buffer.append(" int a[10]; \n"); //$NON-NLS-1$
buffer.append(" for( int i = 0; i < 10; i++ )\n"); //$NON-NLS-1$
buffer.append(" a[i] = 1; \n"); //$NON-NLS-1$
buffer.append(" int j = i; \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
CPPNameCollector col = new CPPNameCollector();
tu.getVisitor().visitTranslationUnit(col);
IVariable i1 = (IVariable) col.getName(1).resolveBinding();
IVariable i2 = (IVariable) col.getName(3).resolveBinding();
assertNotSame( i1, i2 );
assertInstances( col, i1, 2 );
assertInstances( col, i2, 4 );
}
}

View file

@ -602,6 +602,8 @@ public class CPPVisitor implements ICPPASTVisitor {
if( parent instanceof IASTCompoundStatement ){
IASTCompoundStatement compound = (IASTCompoundStatement) parent;
scope = compound.getScope();
} else if( parent instanceof IASTForStatement ){
scope = ((IASTForStatement)parent).getScope();
} else if( parent instanceof IASTStatement ){
scope = getContainingScope( (IASTStatement)parent );
} else if( parent instanceof IASTFunctionDefinition ){