Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ void CheckOtherImpl::checkRedundantAssignment()
if (Token::Match(rhs, ":: %name%") && rhs->hasKnownIntValue())
return ChildrenToVisit::none;
if (rhs->isCast())
return ChildrenToVisit::op2;
return rhs->astOperand2() ? ChildrenToVisit::op2 : ChildrenToVisit::op1;
trivial = false;
return ChildrenToVisit::done;
});
Expand Down
17 changes: 17 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11462,6 +11462,23 @@ class TestOther : public TestFixture {
" return i;\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("int f(char c) {\n" // #15037
" int i = (int)c;\n"
" i = 3;\n"
" return i;\n"
"}\n"
"int g(char c) {\n"
" int i = static_cast<int>(c);\n"
" i = 3;\n"
" return i;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3:7]: style: Redundant initialization for 'i'. The initialized value is overwritten before it is read. [redundantInitialization]\n"
"[test.cpp:2:11]: note: i is initialized\n"
"[test.cpp:3:7]: note: i is overwritten\n"
"[test.cpp:8:8]: style: Redundant initialization for 'i'. The initialized value is overwritten before it is read. [redundantInitialization]\n"
"[test.cpp:7:12]: note: i is initialized\n"
"[test.cpp:8:8]: note: i is overwritten\n", errout_str());
}

// cppcheck-suppress unusedPrivateFunction
Expand Down
Loading