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$
|
buffer.append( "int A::B<int>::* b; \n"); //$NON-NLS-1$
|
||||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
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 ){
|
if( declarations != null ){
|
||||||
for( int j = 0; j < declarations.length && declarations[j] != null; j++ ){
|
for( int j = 0; j < declarations.length && declarations[j] != null; j++ ){
|
||||||
temp = declarations[j].getParameters()[i];
|
IASTParameterDeclaration [] paramDecls = declarations[j].getParameters();
|
||||||
IASTName n = temp.getDeclarator().getName();
|
if( paramDecls.length > i ) {
|
||||||
if( n != name ) {
|
temp = paramDecls[i];
|
||||||
n.setBinding( binding );
|
IASTName n = temp.getDeclarator().getName();
|
||||||
((CPPParameter)binding).addDeclaration( n );
|
if( n != name ) {
|
||||||
}
|
n.setBinding( binding );
|
||||||
|
((CPPParameter)binding).addDeclaration( n );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return binding;
|
return binding;
|
||||||
|
@ -397,9 +399,9 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction {
|
||||||
IASTParameterDeclaration [] ops = orig.getParameters();
|
IASTParameterDeclaration [] ops = orig.getParameters();
|
||||||
IASTParameterDeclaration [] nps = fdtor.getParameters();
|
IASTParameterDeclaration [] nps = fdtor.getParameters();
|
||||||
CPPParameter temp = null;
|
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();
|
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();
|
IASTDeclarator dtor = nps[i].getDeclarator();
|
||||||
while( dtor.getNestedDeclarator() != null )
|
while( dtor.getNestedDeclarator() != null )
|
||||||
dtor = dtor.getNestedDeclarator();
|
dtor = dtor.getNestedDeclarator();
|
||||||
|
|
|
@ -2792,9 +2792,14 @@ public class CPPSemantics {
|
||||||
if( exp instanceof IASTLiteralExpression &&
|
if( exp instanceof IASTLiteralExpression &&
|
||||||
((IASTLiteralExpression)exp).getKind() == IASTLiteralExpression.lk_integer_constant )
|
((IASTLiteralExpression)exp).getKind() == IASTLiteralExpression.lk_integer_constant )
|
||||||
{
|
{
|
||||||
if( Integer.decode( exp.toString() ).intValue() == 0 ){
|
try {
|
||||||
cost.rank = Cost.CONVERSION_RANK;
|
String val = exp.toString().toLowerCase().replace('u', '0');
|
||||||
cost.conversion = 1;
|
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 ){
|
} else if( sPrev instanceof IPointerType && s instanceof ICPPClassType ){
|
||||||
|
|
|
@ -685,7 +685,7 @@ public class CPPVisitor {
|
||||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent;
|
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent;
|
||||||
if( dtor.getNestedDeclarator() == null ) {
|
if( dtor.getNestedDeclarator() == null ) {
|
||||||
while( parent.getParent() instanceof IASTDeclarator )
|
while( parent.getParent() instanceof IASTDeclarator )
|
||||||
parent = (ICPPASTFunctionDeclarator) parent.getParent();
|
parent = (IASTDeclarator) parent.getParent();
|
||||||
ASTNodeProperty prop = parent.getPropertyInParent();
|
ASTNodeProperty prop = parent.getPropertyInParent();
|
||||||
if( prop == IASTSimpleDeclaration.DECLARATOR )
|
if( prop == IASTSimpleDeclaration.DECLARATOR )
|
||||||
return dtor.getFunctionScope();
|
return dtor.getFunctionScope();
|
||||||
|
|
Loading…
Add table
Reference in a new issue