Fixed #9261 (Inconsistent violation report between using global enum and namespaced enum.)

This commit is contained in:
Daniel Marjamäki 2019-10-20 07:07:38 +02:00
parent 4943771e41
commit 00fae7fb42
2 changed files with 10 additions and 0 deletions

View File

@ -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;

View File

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