From d02fb6433da841c8da906a0241e4849cfc07d8b8 Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Tue, 21 Apr 2009 00:37:15 +0000 Subject: [272995] - fixed f.p. and f.n --- .../sample/StatementHasNoEffectChecker.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'codan') diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/StatementHasNoEffectChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/StatementHasNoEffectChecker.java index 7f8528e3b02..14d4d61a078 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/StatementHasNoEffectChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/StatementHasNoEffectChecker.java @@ -15,9 +15,14 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; +import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; +import org.eclipse.cdt.core.dom.ast.IBasicType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression; /** * Checker that detects statements without effect such as @@ -66,7 +71,21 @@ public class StatementHasNoEffectChecker extends AbstractIndexAstChecker { private boolean hasNoEffect(IASTExpression e) { if (e instanceof IASTBinaryExpression) { IASTBinaryExpression binExpr = (IASTBinaryExpression) e; - return binExpr.getOperator() != IASTBinaryExpression.op_assign; + if (binExpr.getOperator() == IASTBinaryExpression.op_assign) + return false; + if (binExpr instanceof CPPASTBinaryExpression) { + CPPASTBinaryExpression cppBin = (CPPASTBinaryExpression) binExpr; + ICPPFunction overload = cppBin.getOverload(); + if (overload != null) + return false; + IType expressionType = binExpr.getOperand1() + .getExpressionType(); + if (!(expressionType instanceof IBasicType)) { + return false; // must be overloaded but parser could not + // find it + } + } + return true; } if (e instanceof IASTUnaryExpression) { IASTUnaryExpression unaryExpr = (IASTUnaryExpression) e; @@ -80,6 +99,10 @@ public class StatementHasNoEffectChecker extends AbstractIndexAstChecker { } return true; } + if (e instanceof IASTIdExpression) { + // simply a; + return true; + } return false; } } -- cgit v1.2.3