mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
fix lookup of names in a declaration that come after a qualified name (bug 90610)
This commit is contained in:
parent
adf20e84c7
commit
ed7f696045
4 changed files with 57 additions and 31 deletions
|
@ -74,37 +74,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
[--Start Example(CPP 3.4.3-3):
|
|
||||||
class X { };
|
|
||||||
class C {
|
|
||||||
class X { };
|
|
||||||
static const int number = 50;
|
|
||||||
static X arr[number];
|
|
||||||
};
|
|
||||||
X C::arr[number]; // illformed:
|
|
||||||
// equivalent to: ::X C::arr[C::number];
|
|
||||||
// not to: C::X C::arr[C::number];
|
|
||||||
--End Example]
|
|
||||||
*/
|
|
||||||
public void test3_4_3s3() { // TODO raised bug 90610
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
buffer.append("class X { };\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("class C {\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("class X { };\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("static const int number = 50;\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("static X arr[number];\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("};\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("X C::arr[number]; // illformed:\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("// equivalent to: ::X C::arr[C::number];\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("// not to: C::X C::arr[C::number];\n"); //$NON-NLS-1$
|
|
||||||
try {
|
|
||||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
|
||||||
assertTrue(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
[--Start Example(CPP 6.4-3):
|
[--Start Example(CPP 6.4-3):
|
||||||
int foo() {
|
int foo() {
|
||||||
|
|
|
@ -491,7 +491,33 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
[--Start Example(CPP 3.4.3-3):
|
||||||
|
class X { };
|
||||||
|
class C {
|
||||||
|
class X { };
|
||||||
|
static const int number = 50;
|
||||||
|
static X arr[number];
|
||||||
|
};
|
||||||
|
X C::arr[number]; // illformed:
|
||||||
|
// equivalent to: ::X C::arr[C::number];
|
||||||
|
// not to: C::X C::arr[C::number];
|
||||||
|
--End Example]
|
||||||
|
*/
|
||||||
|
public void test3_4_3s3() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("class X { };\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("class C {\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("class X { };\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("static const int number = 50;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("static X arr[number];\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("};\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("X C::arr[number]; // illformed:\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("// equivalent to: ::X C::arr[C::number];\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("// not to: C::X C::arr[C::number];\n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
[--Start Example(CPP 3_4_3-5):
|
[--Start Example(CPP 3_4_3-5):
|
||||||
|
|
|
@ -3968,4 +3968,22 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertNoProblemBindings( nameResolver );
|
assertNoProblemBindings( nameResolver );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug90610() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("class C { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" static const int n = 1; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" static int arr[ n ]; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("}; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int C::arr[n]; \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
tu.accept(col);
|
||||||
|
|
||||||
|
ICPPField n = (ICPPField) col.getName(1).resolveBinding();
|
||||||
|
assertTrue( n.isStatic() );
|
||||||
|
|
||||||
|
assertInstances( col, n, 3 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
||||||
|
@ -701,6 +702,18 @@ public class CPPVisitor {
|
||||||
IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition)temp).getBody();
|
IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition)temp).getBody();
|
||||||
return body.getScope();
|
return body.getScope();
|
||||||
}
|
}
|
||||||
|
} else if( parent instanceof IASTArrayModifier || parent instanceof IASTInitializer ){
|
||||||
|
IASTNode d = parent.getParent();
|
||||||
|
while( !(d instanceof IASTDeclarator) )
|
||||||
|
d = d.getParent();
|
||||||
|
IASTDeclarator dtor = (IASTDeclarator) d;
|
||||||
|
while( dtor.getNestedDeclarator() != null )
|
||||||
|
dtor = dtor.getNestedDeclarator();
|
||||||
|
IASTName name = dtor.getName();
|
||||||
|
if( name instanceof ICPPASTQualifiedName ){
|
||||||
|
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||||
|
return getContainingScope( ns[ ns.length - 1 ] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if( node instanceof ICPPASTTemplateParameter ){
|
} else if( node instanceof ICPPASTTemplateParameter ){
|
||||||
return CPPTemplates.getContainingScope( node );
|
return CPPTemplates.getContainingScope( node );
|
||||||
|
|
Loading…
Add table
Reference in a new issue