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

fix NPE for 65114. When returning references to the cache, we should also

remove them from the list they are in, so that we never try to return them
again (potentially after they had been reallocated)
This commit is contained in:
Andrew Niefer 2004-06-09 15:45:31 +00:00
parent e9a68a7cbd
commit e9c5a2b928
6 changed files with 35 additions and 5 deletions

View file

@ -971,17 +971,45 @@ public class CompleteParseASTTemplateTest extends CompleteParseBaseTest {
public void testBug64939() throws Exception
{
try{
parse( "template < class T > class A : public A< T * > {}; A<int> a;" ).getDeclarations(); //NON-NLS-1$
parse( "template < class T > class A : public A< T * > {}; A<int> a;" ).getDeclarations(); //$NON-NLS-1$
assertTrue( false );
} catch ( ParserException e ){
assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
}
try{
parse( "template < class T > class A { A<T*> f(); }; A< int > a;" ).getDeclarations(); //NON-NLS-1$
parse( "template < class T > class A { A<T*> f(); }; A< int > a;" ).getDeclarations(); //$NON-NLS-1$
assertTrue( false );
} catch ( ParserException e ){
assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$
}
}
public void testBug65114() throws Exception
{
Writer writer = new StringWriter();
writer.write( "template < typename _Tp, typename _Alloc > class _simple_alloc {}; \n" ); //$NON-NLS-1$
writer.write( "template < int _inst > class __malloc_alloc {}; \n" ); //$NON-NLS-1$
writer.write( "template < typename _Tp, int __inst> \n" ); //$NON-NLS-1$
writer.write( "struct _Alloc_traits { \n" ); //$NON-NLS-1$
writer.write( " typedef _simple_alloc< _Tp, __malloc_alloc<__inst> > _Alloc_type; \n" ); //$NON-NLS-1$
writer.write( "}; \n" ); //$NON-NLS-1$
Iterator i = parse( writer.toString() ).getDeclarations();
IASTTemplateDeclaration simple_alloc = (IASTTemplateDeclaration) i.next();
IASTTemplateDeclaration malloc_alloc = (IASTTemplateDeclaration) i.next();
IASTTemplateDeclaration alloc_traits = (IASTTemplateDeclaration) i.next();
IASTClassSpecifier alloc = (IASTClassSpecifier) alloc_traits.getOwnedDeclaration();
i = alloc_traits.getTemplateParameters();
IASTTemplateParameter _Tp = (IASTTemplateParameter) i.next();
IASTTemplateParameter inst = (IASTTemplateParameter) i.next();
IASTClassSpecifier simple = (IASTClassSpecifier) simple_alloc.getOwnedDeclaration();
IASTClassSpecifier malloc = (IASTClassSpecifier) malloc_alloc.getOwnedDeclaration();
assertAllReferences( 4, createTaskList( new Task( simple ), new Task( _Tp ),
new Task( malloc ), new Task( inst ) ) );
}
}

View file

@ -294,5 +294,6 @@ public abstract class ASTExpression extends ASTNode implements IASTExpression
if( references == null || references.isEmpty() ) return;
for (int i = 0; i < references.size(); ++i)
manager.returnReference( (IASTReference) references.get(i));
references.clear();
}
}

View file

@ -156,6 +156,6 @@ public class ASTSimpleTypeSpecifier extends ASTNode implements IASTSimpleTypeSpe
if( refs == null || refs.isEmpty() ) return;
for( int i = 0; i < refs.size(); ++i )
referenceManager.returnReference( (ASTReference)refs.get(i));
refs.clear();
}
}

View file

@ -231,7 +231,7 @@ public class ASTTypeId implements IASTTypeId
if( references.isEmpty() ) return;
for( int i =0; i < references.size(); ++i)
manager.returnReference( (IASTReference) references.get(i));
references.clear();
}

View file

@ -3450,7 +3450,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( refs == null || refs.isEmpty() ) return;
for( int i =0; i < refs.size(); ++i)
cache.returnReference((IASTReference) refs.get(i));
refs.clear();
}
/* (non-Javadoc)

View file

@ -112,6 +112,7 @@ public class TemplateTokenDuple extends BasicTokenDuple {
{
IASTExpression e = (IASTExpression) argLists[i].get(j);
e.freeReferences(manager);
}
}
}