From 87354bf9d2267cc659b98938b9fc44b73b13e128 Mon Sep 17 00:00:00 2001 From: Frank Zingsheim Date: Wed, 23 Apr 2014 07:58:43 +0200 Subject: [PATCH] Fixed #5707 (false negative: unreachable code is not detected (code after return)) --- lib/checkother.cpp | 1 + test/testother.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ebc90e7b5..d1e9630d3 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1619,6 +1619,7 @@ void CheckOther::checkUnreachableCode() if (!tok) break; + tok = tok->previous(); // Will be advanced again by for loop } } } diff --git a/test/testother.cpp b/test/testother.cpp index 205691487..2c356552b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3079,6 +3079,17 @@ private: "}", 0, false, false, false, false); ASSERT_EQUALS("[test.cpp:4]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout.str()); + // #5707 + check("extern int i,j\n" + "int foo() {\n" + " switch(i) {\n" + " default: j=1; break;\n" + " }\n" + " return 0;\n" + " j=2;\n" + "}", 0, false, false, false, false); + ASSERT_EQUALS("[test.cpp:7]: (style) Statements following return, break, continue, goto or throw will never be executed.\n", errout.str()); + check("int foo() {\n" " return 0;\n" " label:\n"