Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorMarco Stornelli2020-01-12 18:51:03 +0000
committerMarco Stornelli2020-01-12 18:51:03 +0000
commit4e73ec9cc6d32af73376be445c6348854c6c5e3d (patch)
tree938bfaaa33907647c5e9897cfc3902f6b2b7ad17 /codan
parentabb0b06e2f60cdf3867a3ad8d87b8dd1d0f468fd (diff)
downloadorg.eclipse.cdt-4e73ec9cc6d32af73376be445c6348854c6c5e3d.tar.gz
org.eclipse.cdt-4e73ec9cc6d32af73376be445c6348854c6c5e3d.tar.xz
org.eclipse.cdt-4e73ec9cc6d32af73376be445c6348854c6c5e3d.zip
Bug 559007 - Fix label and tests
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CStyleCastChecker.java7
-rw-r--r--codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/CStyleCastCheckerTest.java17
2 files changed, 20 insertions, 4 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CStyleCastChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CStyleCastChecker.java
index fbcd2f4e9da..54ccfc8b593 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CStyleCastChecker.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CStyleCastChecker.java
@@ -29,12 +29,10 @@ public class CStyleCastChecker extends AbstractIndexAstChecker {
@Override
public void initPreferences(IProblemWorkingCopy problem) {
super.initPreferences(problem);
- addPreference(problem, PARAM_MACRO, CheckersMessages.Copyright_regex, true);
+ addPreference(problem, PARAM_MACRO, CheckersMessages.CStyleCastCheck_checkInMacro, true);
}
private boolean enclosedInMacroExpansion(IASTExpression statement) {
- if (!checkMacro)
- return false;
IASTNodeLocation[] locations = statement.getNodeLocations();
return locations.length == 1 && locations[0] instanceof IASTMacroExpansionLocation;
}
@@ -51,7 +49,8 @@ public class CStyleCastChecker extends AbstractIndexAstChecker {
@Override
public int visit(IASTExpression expression) {
- if (expression instanceof IASTCastExpression && !enclosedInMacroExpansion(expression)) {
+ if (expression instanceof IASTCastExpression
+ && (checkMacro || !enclosedInMacroExpansion(expression))) {
if (((IASTCastExpression) expression).getOperator() == IASTCastExpression.op_cast)
reportProblem(ERR_ID, expression);
}
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/CStyleCastCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/CStyleCastCheckerTest.java
index 3adf4e7d079..ceef770005d 100644
--- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/CStyleCastCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/CStyleCastCheckerTest.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.codan.core.internal.checkers;
+import org.eclipse.cdt.codan.core.param.IProblemPreference;
import org.eclipse.cdt.codan.core.tests.CheckerTestCase;
import org.eclipse.cdt.codan.internal.checkers.CStyleCastChecker;
import org.eclipse.cdt.codan.internal.checkers.UsingInHeaderChecker;
@@ -27,6 +28,11 @@ public class CStyleCastCheckerTest extends CheckerTestCase {
enableProblems(ERR_ID);
}
+ private void setCheckInMacro(boolean val) {
+ IProblemPreference pref = getPreference(CStyleCastChecker.ERR_ID, CStyleCastChecker.PARAM_MACRO);
+ pref.setValue(val);
+ }
+
@Override
public boolean isCpp() {
return true;
@@ -55,6 +61,17 @@ public class CStyleCastCheckerTest extends CheckerTestCase {
//};
public void testInMacro() throws Exception {
loadCodeAndRun(getAboveComment());
+ checkErrorLine(4, ERR_ID);
+ }
+
+ //#define CAST(X) (void)X
+ //void bar() {
+ // int b;
+ // CAST(b);
+ //};
+ public void testInMacroOptionOff() throws Exception {
+ setCheckInMacro(false);
+ loadCodeAndRun(getAboveComment());
checkNoErrorsOfKind(ERR_ID);
}
}

Back to the top