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:
parent
63c073e3a0
commit
4dfe0944bc
3 changed files with 45 additions and 1 deletions
|
@ -1763,4 +1763,37 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
assertTrue( ns[1] instanceof ICPPASTTemplateId );
|
assertTrue( ns[1] instanceof ICPPASTTemplateId );
|
||||||
assertEquals( ((ICPPASTTemplateId)ns[1]).toString(), "B" );
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,10 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
|
||||||
{
|
{
|
||||||
IBinding binding = name.resolveBinding();
|
IBinding binding = name.resolveBinding();
|
||||||
if( binding == CPPClassTemplate.this ){
|
if( binding == CPPClassTemplate.this ){
|
||||||
|
if( name instanceof ICPPASTQualifiedName ){
|
||||||
|
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||||
|
name = ns[ ns.length - 1 ];
|
||||||
|
}
|
||||||
result = name;
|
result = name;
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
}
|
}
|
||||||
|
@ -164,7 +168,11 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
|
||||||
|
|
||||||
private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(){
|
private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(){
|
||||||
if( definition != null ){
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,9 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I
|
||||||
public CPPTemplateDefinition( IASTName name ) {
|
public CPPTemplateDefinition( IASTName name ) {
|
||||||
if( name != null ){
|
if( name != null ){
|
||||||
ASTNodeProperty prop = name.getPropertyInParent();
|
ASTNodeProperty prop = name.getPropertyInParent();
|
||||||
|
if( prop == ICPPASTQualifiedName.SEGMENT_NAME ){
|
||||||
|
prop = name.getParent().getPropertyInParent();
|
||||||
|
}
|
||||||
if( prop == IASTCompositeTypeSpecifier.TYPE_NAME ){
|
if( prop == IASTCompositeTypeSpecifier.TYPE_NAME ){
|
||||||
definition = name;
|
definition = name;
|
||||||
} else if( prop == IASTElaboratedTypeSpecifier.TYPE_NAME ) {
|
} else if( prop == IASTElaboratedTypeSpecifier.TYPE_NAME ) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue