From 2716b856f410a4235eea775f03b23de1dbe85310 Mon Sep 17 00:00:00 2001 From: Greg Hewgill Date: Sat, 12 Mar 2011 07:27:31 +1300 Subject: [PATCH] throwing an exception is a valid immediate exit from switch --- lib/checkother.cpp | 4 ++-- test/testother.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 4bd2973fc..3b1de7923 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -270,7 +270,7 @@ void CheckOther::checkSizeofForArrayParameter() void CheckOther::checkRedundantAssignmentInSwitch() { 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% ("; // Find the beginning of a switch. E.g.: @@ -348,7 +348,7 @@ void CheckOther::checkSwitchCaseFallThrough() return; 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.: // switch (var) { ... diff --git a/test/testother.cpp b/test/testother.cpp index d6fb26305..c3cbdd815 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1180,6 +1180,22 @@ private: "}\n"); 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" "{\n" " int y = 1;\n" @@ -1222,6 +1238,27 @@ private: "}\n"); 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( "void foo() {\n" " switch (a) {\n"