From 00fae7fb428b0b055135d6b972a1b52dd2c08d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 20 Oct 2019 07:07:38 +0200 Subject: [PATCH] Fixed #9261 (Inconsistent violation report between using global enum and namespaced enum.) --- lib/checkother.cpp | 2 ++ test/testother.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 05955edd4..f3dbb07dd 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -443,6 +443,8 @@ void CheckOther::checkRedundantAssignment() return ChildrenToVisit::none; if (Token::Match(rhs, "%str%|%num%|%name%") && !rhs->varId()) return ChildrenToVisit::none; + if (Token::Match(rhs, ":: %name%") && rhs->hasKnownIntValue()) + return ChildrenToVisit::none; if (rhs->isCast()) return ChildrenToVisit::op2; trivial = false; diff --git a/test/testother.cpp b/test/testother.cpp index fc7f5d484..3e6d7b360 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6679,11 +6679,19 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + // "trivial" initialization => do not warn check("void f() {\n" " struct S s = {0};\n" " s = dostuff();\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("namespace N { enum E {e0,e1}; }\n" + "void f() {\n" + " N::E e = N::e0;\n" // #9261 + " e = dostuff();\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void redundantMemWrite() {