mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
fix bug 98998 (ClassCastException). Also fix ArrayIndexOutOfBounds Exceptions
This commit is contained in:
parent
fa2c1a50ab
commit
f875db0ab0
4 changed files with 35 additions and 13 deletions
|
@ -4643,4 +4643,19 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
buffer.append( "int A::B<int>::* b; \n"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
}
|
||||
|
||||
public void testBug_AIOOBE() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("void f(); \n");
|
||||
buffer.append("void f( void ) {} \n");
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
IFunction f = (IFunction) col.getName(0).resolveBinding();
|
||||
assertSame( f, col.getName(1).resolveBinding() );
|
||||
IParameter p = (IParameter) col.getName(2).resolveBinding();
|
||||
assertNotNull( p );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -380,13 +380,15 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction {
|
|||
}
|
||||
if( declarations != null ){
|
||||
for( int j = 0; j < declarations.length && declarations[j] != null; j++ ){
|
||||
temp = declarations[j].getParameters()[i];
|
||||
IASTName n = temp.getDeclarator().getName();
|
||||
if( n != name ) {
|
||||
n.setBinding( binding );
|
||||
((CPPParameter)binding).addDeclaration( n );
|
||||
}
|
||||
|
||||
IASTParameterDeclaration [] paramDecls = declarations[j].getParameters();
|
||||
if( paramDecls.length > i ) {
|
||||
temp = paramDecls[i];
|
||||
IASTName n = temp.getDeclarator().getName();
|
||||
if( n != name ) {
|
||||
n.setBinding( binding );
|
||||
((CPPParameter)binding).addDeclaration( n );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return binding;
|
||||
|
@ -397,9 +399,9 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction {
|
|||
IASTParameterDeclaration [] ops = orig.getParameters();
|
||||
IASTParameterDeclaration [] nps = fdtor.getParameters();
|
||||
CPPParameter temp = null;
|
||||
for( int i = 0; i < nps.length; i++ ){
|
||||
for( int i = 0; i < ops.length; i++ ){
|
||||
temp = (CPPParameter) ops[i].getDeclarator().getName().getBinding();
|
||||
if( temp != null ){
|
||||
if( temp != null && nps.length > i ){ //length could be different, ie 0 or 1 with void
|
||||
IASTDeclarator dtor = nps[i].getDeclarator();
|
||||
while( dtor.getNestedDeclarator() != null )
|
||||
dtor = dtor.getNestedDeclarator();
|
||||
|
|
|
@ -2792,9 +2792,14 @@ public class CPPSemantics {
|
|||
if( exp instanceof IASTLiteralExpression &&
|
||||
((IASTLiteralExpression)exp).getKind() == IASTLiteralExpression.lk_integer_constant )
|
||||
{
|
||||
if( Integer.decode( exp.toString() ).intValue() == 0 ){
|
||||
cost.rank = Cost.CONVERSION_RANK;
|
||||
cost.conversion = 1;
|
||||
try {
|
||||
String val = exp.toString().toLowerCase().replace('u', '0');
|
||||
val.replace( 'l', '0' );
|
||||
if( Integer.decode( val ).intValue() == 0 ){
|
||||
cost.rank = Cost.CONVERSION_RANK;
|
||||
cost.conversion = 1;
|
||||
}
|
||||
} catch( NumberFormatException e ) {
|
||||
}
|
||||
}
|
||||
} else if( sPrev instanceof IPointerType && s instanceof ICPPClassType ){
|
||||
|
|
|
@ -685,7 +685,7 @@ public class CPPVisitor {
|
|||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent;
|
||||
if( dtor.getNestedDeclarator() == null ) {
|
||||
while( parent.getParent() instanceof IASTDeclarator )
|
||||
parent = (ICPPASTFunctionDeclarator) parent.getParent();
|
||||
parent = (IASTDeclarator) parent.getParent();
|
||||
ASTNodeProperty prop = parent.getPropertyInParent();
|
||||
if( prop == IASTSimpleDeclaration.DECLARATOR )
|
||||
return dtor.getFunctionScope();
|
||||
|
|
Loading…
Add table
Reference in a new issue