Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlena Laskavaia2010-06-19 18:05:56 +0000
committerAlena Laskavaia2010-06-19 18:05:56 +0000
commitb5a9a032db55a2389fc6fd0d43d2705f43f95fca (patch)
tree21b9d9dca9694f0e8ca9103ba6607a9810db2f5b /codan/org.eclipse.cdt.codan.checkers
parentf912261f970c8f82ef225af4f16d93b8f938be01 (diff)
downloadorg.eclipse.cdt-b5a9a032db55a2389fc6fd0d43d2705f43f95fca.tar.gz
org.eclipse.cdt-b5a9a032db55a2389fc6fd0d43d2705f43f95fca.tar.xz
org.eclipse.cdt-b5a9a032db55a2389fc6fd0d43d2705f43f95fca.zip
Bug 317042 added more cases for assignment in condition checker
Diffstat (limited to 'codan/org.eclipse.cdt.codan.checkers')
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AssignmentInConditionChecker.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AssignmentInConditionChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AssignmentInConditionChecker.java
index 6a17ef83d3c..2a60e140205 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AssignmentInConditionChecker.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AssignmentInConditionChecker.java
@@ -14,10 +14,14 @@ import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
+import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
+import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
+import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
public class AssignmentInConditionChecker extends AbstractIndexAstChecker {
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem"; //$NON-NLS-1$
@@ -51,8 +55,18 @@ public class AssignmentInConditionChecker extends AbstractIndexAstChecker {
private boolean isUsedAsCondition(IASTExpression expression) {
ASTNodeProperty prop = expression.getPropertyInParent();
if (prop == IASTForStatement.CONDITION
- || prop == IASTIfStatement.CONDITION)
+ || prop == IASTIfStatement.CONDITION
+ || prop == IASTWhileStatement.CONDITIONEXPRESSION
+ || prop == IASTDoStatement.CONDITION)
return true;
+ if (prop == IASTUnaryExpression.OPERAND) {
+ IASTUnaryExpression expr = (IASTUnaryExpression) expression
+ .getParent();
+ if (expr.getOperator() == IASTUnaryExpression.op_bracketedPrimary &&
+ expr.getPropertyInParent() == IASTConditionalExpression.LOGICAL_CONDITION) {
+ return true;
+ }
+ }
return false;
}
}

Back to the top