mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 22:35:43 +02:00
Fixed Bug 84476 - [C++ Parser] NPE caused by strange code from C++ 5.11-2
This commit is contained in:
parent
14feb82cc2
commit
887dc877d4
3 changed files with 17 additions and 4 deletions
|
@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
|||
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.IASTDeclarationStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
||||
|
@ -50,6 +51,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.ICPPASTNamedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
|
@ -2082,7 +2084,13 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
buffer.append( "int (B::*pb)() = &B::f;\n"); //$NON-NLS-1$
|
||||
buffer.append( "}\n" ); //$NON-NLS-1$
|
||||
String code = buffer.toString();
|
||||
parse( code, ParserLanguage.CPP );
|
||||
IASTFunctionDefinition foo = (IASTFunctionDefinition) parse( code, ParserLanguage.CPP ).getDeclarations()[0];
|
||||
IASTDeclarationStatement decl = (IASTDeclarationStatement) ((IASTCompoundStatement)foo.getBody()).getStatements()[1];
|
||||
IASTSimpleDeclaration pb = (IASTSimpleDeclaration) decl.getDeclaration();
|
||||
IASTDeclarator d = pb.getDeclarators()[0];
|
||||
assertEquals( d.getNestedDeclarator().getPointerOperators().length, 1 );
|
||||
assertEquals( d.getNestedDeclarator().getName().toString(), "pb" ); //$NON-NLS-1$
|
||||
assertTrue( d.getNestedDeclarator().getPointerOperators()[0] instanceof ICPPASTPointerToMember );
|
||||
}
|
||||
|
||||
public void testBug86336() throws Exception {
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
|
@ -1492,7 +1493,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
if (expressionStatement == null && ds != null) {
|
||||
|
||||
return ds;
|
||||
}
|
||||
if (expressionStatement != null && ds == null) {
|
||||
|
@ -1500,7 +1500,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
if (consume() == lastTokenOfExpression)
|
||||
break;
|
||||
}
|
||||
|
||||
return expressionStatement;
|
||||
}
|
||||
|
||||
|
@ -1518,6 +1517,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
|
||||
return ds;
|
||||
}
|
||||
if( lhs instanceof IASTFunctionCallExpression )
|
||||
{
|
||||
//lvalue - makes no sense
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
if( signature == null ) return ""; //$NON-NLS-1$
|
||||
return signature;
|
||||
}
|
||||
|
||||
|
@ -113,7 +114,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
*/
|
||||
public char[] toCharArray() {
|
||||
if (names == null)
|
||||
return null;
|
||||
return "".toCharArray();
|
||||
removeNullNames();
|
||||
|
||||
//count first
|
||||
|
|
Loading…
Add table
Reference in a new issue