mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-12 02:35:37 +02:00
Bug 559007 - Fix label and tests
Change-Id: I37dd90e972f9ce326695ddd29b49e30c820752cc
This commit is contained in:
parent
abb0b06e2f
commit
4e73ec9cc6
2 changed files with 20 additions and 4 deletions
|
@ -29,12 +29,10 @@ public class CStyleCastChecker extends AbstractIndexAstChecker {
|
||||||
@Override
|
@Override
|
||||||
public void initPreferences(IProblemWorkingCopy problem) {
|
public void initPreferences(IProblemWorkingCopy problem) {
|
||||||
super.initPreferences(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) {
|
private boolean enclosedInMacroExpansion(IASTExpression statement) {
|
||||||
if (!checkMacro)
|
|
||||||
return false;
|
|
||||||
IASTNodeLocation[] locations = statement.getNodeLocations();
|
IASTNodeLocation[] locations = statement.getNodeLocations();
|
||||||
return locations.length == 1 && locations[0] instanceof IASTMacroExpansionLocation;
|
return locations.length == 1 && locations[0] instanceof IASTMacroExpansionLocation;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +49,8 @@ public class CStyleCastChecker extends AbstractIndexAstChecker {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTExpression expression) {
|
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)
|
if (((IASTCastExpression) expression).getOperator() == IASTCastExpression.op_cast)
|
||||||
reportProblem(ERR_ID, expression);
|
reportProblem(ERR_ID, expression);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.internal.checkers;
|
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.core.tests.CheckerTestCase;
|
||||||
import org.eclipse.cdt.codan.internal.checkers.CStyleCastChecker;
|
import org.eclipse.cdt.codan.internal.checkers.CStyleCastChecker;
|
||||||
import org.eclipse.cdt.codan.internal.checkers.UsingInHeaderChecker;
|
import org.eclipse.cdt.codan.internal.checkers.UsingInHeaderChecker;
|
||||||
|
@ -27,6 +28,11 @@ public class CStyleCastCheckerTest extends CheckerTestCase {
|
||||||
enableProblems(ERR_ID);
|
enableProblems(ERR_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setCheckInMacro(boolean val) {
|
||||||
|
IProblemPreference pref = getPreference(CStyleCastChecker.ERR_ID, CStyleCastChecker.PARAM_MACRO);
|
||||||
|
pref.setValue(val);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCpp() {
|
public boolean isCpp() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -54,6 +60,17 @@ public class CStyleCastCheckerTest extends CheckerTestCase {
|
||||||
// CAST(b);
|
// CAST(b);
|
||||||
//};
|
//};
|
||||||
public void testInMacro() throws Exception {
|
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());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkNoErrorsOfKind(ERR_ID);
|
checkNoErrorsOfKind(ERR_ID);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue