Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2015-02-15 01:50:32 +0000
committerGerrit Code Review @ Eclipse.org2015-02-16 06:48:37 +0000
commit0221ee20b17cae754bbc07fa8ec97671c7ed4b19 (patch)
tree9111f55979f741fd883d08f9e0796fa9985cfa2e /codan/org.eclipse.cdt.codan.checkers
parent155fa65c1c0d8190fc9d377963d95a8ac98ebb6c (diff)
downloadorg.eclipse.cdt-0221ee20b17cae754bbc07fa8ec97671c7ed4b19.tar.gz
org.eclipse.cdt-0221ee20b17cae754bbc07fa8ec97671c7ed4b19.tar.xz
org.eclipse.cdt-0221ee20b17cae754bbc07fa8ec97671c7ed4b19.zip
Bug 441714 - Consider spurious semicolons in CaseBreakChecker
Change-Id: Id4fe394164063007c45da37ae82cc730a9e726dd Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
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/CaseBreakChecker.java11
1 files changed, 11 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java
index 2c528ab5153..7d3a6beb854 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java
@@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
+import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
@@ -90,6 +91,9 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
IASTStatement next = null;
if (i < statements.length - 1)
next = statements[i + 1];
+ IASTStatement prev = null;
+ if (i > 0)
+ prev = statements[i - 1];
if (isCaseStatement(curr)) {
prevCase = curr;
}
@@ -102,6 +106,13 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
if (!fCheckLastCase && next == null) {
continue; // Last case and we don't care
}
+ // If this is the null statement, base the decision on the previous statement
+ // instead (if there is one). Null statements can sneak in via macros in cases
+ // where the macro expansion ends in a semicolon, and the macro use is followed
+ // by a semicolon as well.
+ if (curr instanceof IASTNullStatement && (prev != prevCase)) {
+ curr = prev;
+ }
if (!isProducedByMacroExpansion(prevCase) && isFallThroughStamement(curr)) {
IASTComment comment = null;
if (next != null) {

Back to the top