1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

fix ClassCastExceptions found with bug 90678

This commit is contained in:
Andrew Niefer 2005-06-21 15:41:49 +00:00
parent 63c073e3a0
commit 4dfe0944bc
3 changed files with 45 additions and 1 deletions

View file

@ -1763,4 +1763,37 @@ public class AST2TemplateTests extends AST2BaseTest {
assertTrue( ns[1] instanceof ICPPASTTemplateId );
assertEquals( ((ICPPASTTemplateId)ns[1]).toString(), "B" );
}
public void testBug90678() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template <class T> struct A{ \n");
buffer.append(" class C { \n");
buffer.append(" template <class T2> struct B {}; \n");
buffer.append(" }; \n");
buffer.append("}; \n");
buffer.append("template <class T> template <class T2> \n");
buffer.append("struct A<T>::C::B<T2*>{}; \n");
buffer.append("A<short>::C::B<int*> ab; \n");
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector();
tu.accept( col );
ICPPTemplateParameter T = (ICPPTemplateParameter) col.getName(0).resolveBinding();
ICPPTemplateParameter T2 = (ICPPTemplateParameter) col.getName(3).resolveBinding();
ICPPClassTemplate B = (ICPPClassTemplate) col.getName(4).resolveBinding();
assertSame( T, col.getName(5).resolveBinding() );
assertSame( T2, col.getName(6).resolveBinding() );
assertSame( T, col.getName(10).resolveBinding() );
assertSame( T2, col.getName(14).resolveBinding() );
ICPPClassTemplatePartialSpecialization spec = (ICPPClassTemplatePartialSpecialization) col.getName(12).resolveBinding();
assertSame( spec.getPrimaryClassTemplate(), B );
ICPPClassType BI = (ICPPClassType) col.getName(19).resolveBinding();
assertTrue( BI instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)BI).getSpecializedBinding(), spec );
}
}

View file

@ -109,6 +109,10 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
{
IBinding binding = name.resolveBinding();
if( binding == CPPClassTemplate.this ){
if( name instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
name = ns[ ns.length - 1 ];
}
result = name;
return PROCESS_ABORT;
}
@ -164,7 +168,11 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(){
if( definition != null ){
return (ICPPASTCompositeTypeSpecifier) definition.getParent();
IASTNode node = definition.getParent();
if( node instanceof ICPPASTQualifiedName )
node = node.getParent();
if( node instanceof ICPPASTCompositeTypeSpecifier )
return (ICPPASTCompositeTypeSpecifier) node;
}
return null;
}

View file

@ -78,6 +78,9 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I
public CPPTemplateDefinition( IASTName name ) {
if( name != null ){
ASTNodeProperty prop = name.getPropertyInParent();
if( prop == ICPPASTQualifiedName.SEGMENT_NAME ){
prop = name.getParent().getPropertyInParent();
}
if( prop == IASTCompositeTypeSpecifier.TYPE_NAME ){
definition = name;
} else if( prop == IASTElaboratedTypeSpecifier.TYPE_NAME ) {