Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AssignmentInConditionChecker.java6
-rw-r--r--codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentInConditionCheckerTest.java49
2 files changed, 55 insertions, 0 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 a0ee541c049..32be3cc4b25 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
@@ -20,6 +20,7 @@ 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.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@@ -52,6 +53,11 @@ public class AssignmentInConditionChecker extends AbstractIndexAstChecker {
if (e instanceof IASTBinaryExpression) {
IASTBinaryExpression binExpr = (IASTBinaryExpression) e;
return binExpr.getOperator() == IASTBinaryExpression.op_assign;
+ } else if (e instanceof IASTExpressionList) {
+ for (IASTExpression expr : ((IASTExpressionList) e).getExpressions()) {
+ if (isAssignmentExpression(expr))
+ return true;
+ }
}
return false;
}
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentInConditionCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentInConditionCheckerTest.java
index c7ad4ebaa64..afdaee4b1a4 100644
--- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentInConditionCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentInConditionCheckerTest.java
@@ -16,6 +16,7 @@ package org.eclipse.cdt.codan.core.internal.checkers;
import org.eclipse.cdt.codan.core.tests.CheckerTestCase;
import org.eclipse.cdt.codan.internal.core.model.CodanProblemMarker;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
/**
* Test for {@see AssignmentInConditionChecker} class
@@ -143,4 +144,52 @@ public class AssignmentInConditionCheckerTest extends CheckerTestCase {
loadCodeAndRun(getAboveComment());
checkErrorLine(4);
}
+
+ //void test_commaPrecededIf() {
+ // int a, b;
+ // if (a=some_value(), b=some_other_value(), a=b){ // warning here
+ // // do something
+ // }else{
+ // // do something else
+ // }
+ //}
+ //int some_value(){return 0;}
+ //int ome_other_value(){return 1;}
+ public void test_commaPrecededIf() throws CoreException {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(3);
+ }
+
+ //void test_commaPrecededWhile() {
+ // int NO_ERROR = 0;
+ // int error_code;
+ // while (error_code = read_from_file(), error_code = NO_ERROR) { // warning
+ // // do something
+ // }
+ //}
+ public void test_commaPrecededWhile() throws CoreException {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(4);
+ }
+
+ //void test_commaPrecededDoWhile() {
+ // int NO_ERROR = 0;
+ // int error_code;
+ // do{
+ // // do something
+ // } while (error_code = read_from_file(), error_code = NO_ERROR); // warning
+ //}
+ public void test_commaPrecededDoWhile() throws CoreException {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(6);
+ }
+
+ //void test_commaPrecededConditioal(){
+ // int a, b, c;
+ // c = (a=some_value(), b=some_other_value(), a=b)? a : b; // warning here
+ //}
+ public void test_commaPrecededConditioal() throws CoreException {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(3);
+ }
}

Back to the top