mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 16:56:04 +02:00
bug 67680 - better error handling around problems in the base clause specifier
fixes class cast exception
This commit is contained in:
parent
77483762af
commit
0454da5130
3 changed files with 34 additions and 5 deletions
|
@ -1947,4 +1947,24 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
|
|||
{
|
||||
parse( "const char * x = __FILE__;"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testBug67680() throws Exception
|
||||
{
|
||||
Writer writer = new StringWriter();
|
||||
writer.write( "template < class T> class Base {}; \n" );
|
||||
writer.write( "class Derived : public Base, Base<int>, foo {}; \n" );
|
||||
|
||||
Iterator i = parse( writer.toString(), false ).getDeclarations();
|
||||
|
||||
IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next();
|
||||
IASTClassSpecifier base = (IASTClassSpecifier) template.getOwnedDeclaration();
|
||||
IASTClassSpecifier derived = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
|
||||
//only Base<int> is a valid parent, Base and foo are not expected to show up in the iterator.
|
||||
i = derived.getBaseClauses();
|
||||
IASTBaseSpecifier parent = (IASTBaseSpecifier) i.next();
|
||||
assertFalse( i.hasNext() );
|
||||
|
||||
assertEquals( parent.getParentClassSpecifier(), base );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2856,10 +2856,14 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
int size = bases.size();
|
||||
for( int i = 0; i < size; i++ ){
|
||||
Object [] data = (Object[]) bases.get( i );
|
||||
astFactory.addBaseSpecifier( astClassSpec,
|
||||
((Boolean)data[0]).booleanValue(),
|
||||
(ASTAccessVisibility) data[1],
|
||||
(ITokenDuple)data[2] );
|
||||
try {
|
||||
astFactory.addBaseSpecifier( astClassSpec,
|
||||
((Boolean)data[0]).booleanValue(),
|
||||
(ASTAccessVisibility) data[1],
|
||||
(ITokenDuple)data[2] );
|
||||
} catch (ASTSemanticException e1) {
|
||||
failParse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2872,7 +2876,6 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
catch (ASTSemanticException e)
|
||||
{
|
||||
failParse();
|
||||
throwBacktrack(e.getProblem());
|
||||
} catch (Exception e)
|
||||
{
|
||||
logException( "baseSpecifier_2::addBaseSpecifier", e ); //$NON-NLS-1$
|
||||
|
|
|
@ -931,6 +931,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
|
||||
//Its possible that the parent is not an IContainerSymbol if its a template parameter or some kinds of template instances
|
||||
ISymbol symbol = lookupQualifiedName( classSymbol, parentClassName, references, true );
|
||||
|
||||
if( symbol == null )
|
||||
handleProblem( IProblem.SEMANTIC_NAME_NOT_FOUND,parentClassName.toString(), parentClassName.getStartOffset(), parentClassName.getEndOffset(), parentClassName.getLineNumber(), true);
|
||||
else if( symbol instanceof ITemplateSymbol )
|
||||
handleProblem( IProblem.SEMANTIC_INVALID_TEMPLATE_ARGUMENT, parentClassName.toString(), parentClassName.getStartOffset(), parentClassName.getEndOffset(), parentClassName.getLineNumber(), true);
|
||||
|
||||
List [] templateArgumentLists = parentClassName.getTemplateIdArgLists();
|
||||
if( templateArgumentLists != null )
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue