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() {