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
3 changes: 2 additions & 1 deletion lib/vf_analyzers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ struct ValueFlowAnalyzer : Analyzer {
if (inconclusive)
return Action::Read | Action::Inconclusive;
if (isVariableChanged(tok, getIndirect(tok), getSettings())) {
if (Token::Match(tok->astParent(), "*|[|.|++|--"))
if (Token::Match(tok->astParent(), "*|[|.|++|--") ||
(tok->astParent() && tok->astParent()->isAssignmentOp() && tok->astParent()->str().size() == 2)) // compound assignment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

str().size() == 2 misses <<= and >>= (both 3 characters). For a moved S x with S& operator<<=(int), x <<= 1; still gets no accessMoved, while x += 1; now does. With uninitialized ints, x += y now gives uninitvar but x <<= y stays legacyUninitvar. tok->astParent()->str() != "=" would cover all compound assignments.

return Action::Read | Action::Invalid;
// Check if its assigned to the same value
if (value && !value->isImpossible() && Token::simpleMatch(tok->astParent(), "=") && astIsLHS(tok) &&
Expand Down
2 changes: 1 addition & 1 deletion test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4707,7 +4707,7 @@ class TestNullPointer : public TestFixture {
" p += a;\n"
" *p = 0;\n"
"}\n");
ASSERT_EQUALS("", errout_str());
ASSERT_EQUALS("[test.cpp:2:7]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str());

check("int f(int *p = 0) {\n"
" if (p == 0) {\n"
Expand Down
6 changes: 6 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,12 @@ class TestValueFlow : public TestFixture {
" g(std::move(x)).f(1);\n"
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MoveKind::MovedVariable));

code = "void f(std::string x) {\n" // #15155
" std::string a{ std::move(x) };\n"
" x += \"abc\";\n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 3U, ValueFlow::Value::MoveKind::MovedVariable));
}

void valueFlowCalculations() {
Expand Down
Loading