Skip to content

Commit

Permalink
Merge pull request #360 from UnrealQuester/switch_continue
Browse files Browse the repository at this point in the history
Treat continue as a break in switch statement
  • Loading branch information
Ryuichi Saito committed Sep 9, 2016
2 parents fa6a904 + 68ff7a4 commit 0c44958
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class MissingBreakInSwitchStatementRule :
return false;
}

bool VisitContinueStmt(ContinueStmt *)
{
return false;
}

bool VisitCXXThrowExpr(CXXThrowExpr *)
{
return false;
Expand Down Expand Up @@ -93,7 +98,10 @@ class MissingBreakInSwitchStatementRule :
bool isBreakingPoint(Stmt *stmt)
{
return stmt && (isa<BreakStmt>(stmt) ||
isa<ReturnStmt>(stmt) || isa<CXXThrowExpr>(stmt) || isa<ObjCAtThrowStmt>(stmt));
isa<ReturnStmt>(stmt) ||
isa<CXXThrowExpr>(stmt) ||
isa<ContinueStmt>(stmt) ||
isa<ObjCAtThrowStmt>(stmt));
}

bool VisitSwitchStmt(SwitchStmt *switchStmt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ default: \n\
} }");
}

TEST(MissingBreakInSwitchStatementRuleTest, SkipCasesWithContinue)
{
testRuleOnCode(new MissingBreakInSwitchStatementRule(), "int aMethod(int a) {\n\
for(int i=0;i<2;++i) {\n\
\tswitch(a){ \n\
\tcase 1: \n\
\t\tcontinue; \n\
\tcase 2: \n\
\t\tcontinue; \n\
\tdefault: \n\
\t\tcontinue; \n\
} } }");
}

/*
Tests for the false positive found by Stephan Esch
Details at https://github.com/oclint/oclint/issues/16
Expand Down

0 comments on commit 0c44958

Please sign in to comment.