mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 22:22:11 +02:00
Bug 428922: Class cast exception parsing expression ambiguity within delete expression.
Signed-off-by: Markus Schorn <markus.schorn@windriver.com>
This commit is contained in:
parent
710efe52ec
commit
d6b443f67a
2 changed files with 32 additions and 1 deletions
|
@ -96,6 +96,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
|
||||
|
@ -6935,6 +6936,23 @@ public class AST2CPPTests extends AST2TestBase {
|
|||
parseAndCheckBindings(code, CPP);
|
||||
}
|
||||
|
||||
// typedef struct xx{} type;
|
||||
// void test(void* ptr) {
|
||||
// delete (type)(ptr);
|
||||
// }
|
||||
public void testAmbiguityResolutionInDeleteExpression_428922() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
BindingAssertionHelper ba= new BindingAssertionHelper(code, true);
|
||||
ba.assertNonProblem("type)", 4, ITypedef.class);
|
||||
ba.assertNonProblem("ptr);", 3, ICPPVariable.class);
|
||||
|
||||
IASTTranslationUnit tu = parseAndCheckBindings(code, CPP);
|
||||
ICPPASTFunctionDefinition test= getDeclaration(tu, 1);
|
||||
IASTExpressionStatement stmt= getStatement(test, 0);
|
||||
ICPPASTDeleteExpression dexpr= (ICPPASTDeleteExpression) stmt.getExpression();
|
||||
assertTrue(dexpr.getOperand() instanceof ICPPASTCastExpression);
|
||||
}
|
||||
|
||||
// void f(int x);
|
||||
//
|
||||
// void test(int* p, const int* q, int r[], const int s[]) {
|
||||
|
|
|
@ -17,18 +17,21 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed;
|
||||
|
||||
|
||||
public class CPPASTDeleteExpression extends ASTNode implements ICPPASTDeleteExpression {
|
||||
public class CPPASTDeleteExpression extends ASTNode implements ICPPASTDeleteExpression, IASTAmbiguityParent {
|
||||
private static final ICPPEvaluation EVALUATION = new EvalFixed(CPPSemantics.VOID_TYPE, PRVALUE, Value.UNKNOWN);
|
||||
|
||||
private IASTExpression operand;
|
||||
|
@ -186,4 +189,14 @@ public class CPPASTDeleteExpression extends ASTNode implements ICPPASTDeleteExpr
|
|||
public ValueCategory getValueCategory() {
|
||||
return PRVALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if (child == operand) {
|
||||
other.setPropertyInParent(child.getPropertyInParent());
|
||||
other.setParent(child.getParent());
|
||||
operand = (IASTExpression) other;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue