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

fix bug 98961 (ClassCastException)

This commit is contained in:
Andrew Niefer 2005-06-08 15:46:00 +00:00
parent 1eb10a46a0
commit 164b25ecae
2 changed files with 40 additions and 8 deletions

View file

@ -1630,4 +1630,31 @@ public class AST2TemplateTests extends AST2BaseTest {
assertSame( foo, col.getName(39).resolveBinding() );
assertSame( foo, col.getName(41).resolveBinding() );
}
public void testBug98961() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("class B { int i; }; \n"); //$NON-NLS-1$
buffer.append("template <class T > class A { \n"); //$NON-NLS-1$
buffer.append(" typedef T* _T; \n"); //$NON-NLS-1$
buffer.append("}; \n"); //$NON-NLS-1$
buffer.append("void f(){ \n"); //$NON-NLS-1$
buffer.append(" A<B>::_T t; \n"); //$NON-NLS-1$
buffer.append(" (*t).i; \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector();
tu.accept( col );
ICPPClassType B = (ICPPClassType) col.getName(0).resolveBinding();
ICPPField i = (ICPPField) col.getName(1).resolveBinding();
ITypedef _T = (ITypedef) col.getName(5).resolveBinding();
ICPPVariable t = (ICPPVariable) col.getName(12).resolveBinding();
IType type = t.getType();
assertTrue( type instanceof ICPPSpecialization );
assertSame( ((ICPPSpecialization)type).getSpecializedBinding(), _T );
assertSame( i, col.getName(14).resolveBinding() );
}
}

View file

@ -22,13 +22,14 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedef.CPPTypedefDelegate;
/**
* @author aniefer
*/
public class CPPTypedefSpecialization extends CPPSpecialization implements
ITypedef {
ITypedef, ITypeContainer {
private IType type = null;
/**
@ -58,13 +59,13 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements
* @see java.lang.Object#clone()
*/
public Object clone() {
// IType t = null;
// try {
// t = (IType) super.clone();
// } catch ( CloneNotSupportedException e ) {
// //not going to happen
// }
return this;
IType t = null;
try {
t = (IType) super.clone();
} catch ( CloneNotSupportedException e ) {
//not going to happen
}
return t;
}
/* (non-Javadoc)
@ -100,4 +101,8 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements
return new CPPTypedefDelegate( name, this );
}
public void setType(IType type) {
this.type = type;
}
}