From e23dc5c1e2c3fedc4a688cd8c6b53d3f93317ba0 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 20 Nov 2016 14:43:54 +0100 Subject: [PATCH] Fixed wrong message shown if unused label appears directly after a switch() scope --- lib/checkother.cpp | 2 +- test/testother.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d36781ad8..918db2387 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2589,7 +2589,7 @@ void CheckOther::checkUnusedLabel() if (Token::Match(tok, "{|}|; %name% :") && tok->strAt(1) != "default") { if (!Token::findsimplematch(scope->classStart->next(), ("goto " + tok->strAt(1)).c_str(), scope->classEnd->previous())) - unusedLabelError(tok->next(), tok->scope()->type == Scope::eSwitch); + unusedLabelError(tok->next(), tok->next()->scope()->type == Scope::eSwitch); } } } diff --git a/test/testother.cpp b/test/testother.cpp index 68a22f70c..56aebe810 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5972,6 +5972,15 @@ private: "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()?\n" "[test.cpp:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()?\n", errout.str()); + + check("int test(char art) {\n" + " switch (art) {\n" + " case 2:\n" + " return 2;\n" + " }\n" + " label:\n" + "}"); + ASSERT_EQUALS("[test.cpp:6]: (style) Label 'label' is not used.\n", errout.str()); } void testEvaluationOrder() {