From 2f66b31d437a08e4647cbfbe9a529c6a06b32013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 24 Nov 2018 21:39:01 +0100 Subject: [PATCH] redundantAssignmentInSwitch: fix false positive when there is goto --- lib/checkother.cpp | 2 +- test/testother.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d669a776b..80b9b4b9b 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -471,7 +471,7 @@ const Token *CheckOther::checkRedundantAssignmentRecursive(const Token *assign1, return nullptr; } - if (Token::Match(tok, "break|continue|return|throw")) { + if (Token::Match(tok, "break|continue|return|throw|goto")) { // TODO: handle these better *read = true; return nullptr; diff --git a/test/testother.cpp b/test/testother.cpp index ec3931dbd..9603ff6de 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1932,6 +1932,14 @@ private: "}\n", nullptr, false, false, true); ASSERT_EQUALS("", errout.str()); + check("void f() {\n" + " int x;\n" + " switch (state) {\n" + " case 1: x = 3; goto a;\n" + " case 1: x = 6; goto a;\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void switchRedundantOperationTest() {