From 70fcbe94f49d81438d5ab7276e8e4e6726d11db9 Mon Sep 17 00:00:00 2001 From: Greg Hewgill Date: Wed, 23 Feb 2011 22:45:21 +1300 Subject: [PATCH] avoid warning on first case (in case there are declarations before first case) --- lib/checkother.cpp | 4 +++- test/testother.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 93480de5e..8324808c5 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -323,6 +323,7 @@ void CheckOther::checkSwitchCaseFallThrough() std::stack loopnest; std::stack scopenest; bool justbreak = true; + bool firstcase = true; for (const Token *tok2 = tok->tokAt(1)->link()->tokAt(2); tok2; tok2 = tok2->next()) { if (Token::Match(tok2, "if (")) @@ -396,12 +397,13 @@ void CheckOther::checkSwitchCaseFallThrough() } else if (Token::Match(tok2, "case|default")) { - if (!justbreak) + if (!justbreak && !firstcase) { switchCaseFallThrough(tok2); } tok2 = Token::findmatch(tok2, ":"); justbreak = true; + firstcase = false; } else if (tok2->str() == "{") { diff --git a/test/testother.cpp b/test/testother.cpp index b65bd7663..e939f0d61 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1383,6 +1383,16 @@ private: " }\n" "}\n"); ASSERT_EQUALS("[test.cpp:5]: (warning) Switch falls through case without comment\n", errout.str()); + + check_preprocess_suppress( + "void foo() {\n" + " switch (a) {\n" + " int x;\n" + " case 1:\n" + " break;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void selfAssignment()