mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 19:35:36 +02:00
fix bug 90498.
a constructor initializer doesnt make sense after a function declarator
This commit is contained in:
parent
c739209ea0
commit
73ca558363
2 changed files with 26 additions and 2 deletions
|
@ -16,6 +16,7 @@ package org.eclipse.cdt.core.parser.tests.ast2;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
|
@ -52,6 +53,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
|
|||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
|
@ -3275,5 +3277,20 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertEquals( expression.getInitialValue(), null );
|
||||
assertEquals( expression.getSimpleType(), ICPPASTSimpleTypeConstructorExpression.t_int );
|
||||
}
|
||||
|
||||
public void testBug90498() throws Exception {
|
||||
IASTTranslationUnit tu = parse( "typedef INT ( FOO ) (INT);", ParserLanguage.CPP ); //$NON-NLS-1$
|
||||
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTDeclSpecifier declSpec = decl.getDeclSpecifier();
|
||||
assertTrue( declSpec instanceof ICPPASTNamedTypeSpecifier );
|
||||
assertEquals( ((ICPPASTNamedTypeSpecifier)declSpec).getName().toString(), "INT" ); //$NON-NLS-1$
|
||||
|
||||
IASTDeclarator dtor = decl.getDeclarators()[0];
|
||||
assertTrue( dtor instanceof IASTFunctionDeclarator );
|
||||
assertNotNull( dtor.getNestedDeclarator() );
|
||||
IASTDeclarator nested = dtor.getNestedDeclarator();
|
||||
assertEquals( nested.getName().toString(), "FOO" ); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
|
@ -3494,7 +3495,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
throws EndOfFileException, BacktrackException {
|
||||
IASTDeclarator d = declarator(strategy, false, false);
|
||||
|
||||
IASTInitializer initializer = optionalCPPInitializer();
|
||||
IASTInitializer initializer = optionalCPPInitializer( d );
|
||||
if (initializer != null) {
|
||||
d.setInitializer(initializer);
|
||||
initializer.setParent(d);
|
||||
|
@ -3506,7 +3507,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return d;
|
||||
}
|
||||
|
||||
protected IASTInitializer optionalCPPInitializer()
|
||||
protected IASTInitializer optionalCPPInitializer( IASTDeclarator d )
|
||||
throws EndOfFileException, BacktrackException {
|
||||
// handle initializer
|
||||
|
||||
|
@ -3520,6 +3521,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
throw eof;
|
||||
}
|
||||
} else if (LT(1) == IToken.tLPAREN) {
|
||||
if( d instanceof IASTFunctionDeclarator ){
|
||||
//constructor initializer doesn't make sense for a function declarator,
|
||||
//C++98:8.5-11 A parenthesized initializer can be a list of expressions
|
||||
//only when the entity has a class type
|
||||
return null;
|
||||
}
|
||||
// initializer in constructor
|
||||
int o = consume(IToken.tLPAREN).getOffset(); // EAT IT!
|
||||
IASTExpression astExpression = expression();
|
||||
|
|
Loading…
Add table
Reference in a new issue