throwing an exception is a valid immediate exit from switch

This commit is contained in:
Greg Hewgill 2011-03-12 07:27:31 +13:00
parent 79f0fe7d1c
commit 2716b856f4
2 changed files with 39 additions and 2 deletions

View File

@ -270,7 +270,7 @@ void CheckOther::checkSizeofForArrayParameter()
void CheckOther::checkRedundantAssignmentInSwitch() void CheckOther::checkRedundantAssignmentInSwitch()
{ {
const char switchPattern[] = "switch ( %any% ) { case"; const char switchPattern[] = "switch ( %any% ) { case";
const char breakPattern[] = "break|continue|return|exit|goto"; const char breakPattern[] = "break|continue|return|exit|goto|throw";
const char functionPattern[] = "%var% ("; const char functionPattern[] = "%var% (";
// Find the beginning of a switch. E.g.: // Find the beginning of a switch. E.g.:
@ -348,7 +348,7 @@ void CheckOther::checkSwitchCaseFallThrough()
return; return;
const char switchPattern[] = "switch ("; const char switchPattern[] = "switch (";
const char breakPattern[] = "break|continue|return|exit|goto"; const char breakPattern[] = "break|continue|return|exit|goto|throw";
// Find the beginning of a switch. E.g.: // Find the beginning of a switch. E.g.:
// switch (var) { ... // switch (var) { ...

View File

@ -1180,6 +1180,22 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("void foo()\n"
"{\n"
" int y = 1;\n"
" while(xyz()) {\n"
" switch (x)\n"
" {\n"
" case 2:\n"
" y = 2;\n"
" throw e;\n"
" case 3:\n"
" y = 3;\n"
" }\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
" int y = 1;\n" " int y = 1;\n"
@ -1222,6 +1238,27 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check_preprocess_suppress(
"void foo() {\n"
" switch (a) {\n"
" case 1:\n"
" break;\n"
" case 2:\n"
" continue;\n"
" case 3:\n"
" return;\n"
" case 4:\n"
" exit(1);\n"
" case 5:\n"
" goto end;\n"
" case 6:\n"
" throw e;\n"
" case 7:\n"
" break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check_preprocess_suppress( check_preprocess_suppress(
"void foo() {\n" "void foo() {\n"
" switch (a) {\n" " switch (a) {\n"