Skip to content
Merged
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
13 changes: 12 additions & 1 deletion lib/vf_analyzers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@
#include <set>
#include <type_traits>

static bool isDereferenceOp(const Token* tok)
{
if (!tok)
return false;
if (!tok->astOperand1())
return false;
if (tok->str() == "*")
return true;
return tok->str() == "." && tok->originalName() == "->";
}

struct ValueFlowAnalyzer : Analyzer {
const Settings& settings;
ProgramMemoryState pms;
Expand Down Expand Up @@ -586,7 +597,7 @@ struct ValueFlowAnalyzer : Analyzer {
} else {
return analyzeMatch(tok, d) | Action::Match;
}
} else if (ref->isUnaryOp("*") && !match(ref->astOperand1())) {
} else if (isDereferenceOp(ref) && !match(ref->astOperand1())) {
const Token* lifeTok = nullptr;
for (const ValueFlow::Value& v:ref->astOperand1()->values()) {
if (!v.isLocalLifetimeValue())
Expand Down
12 changes: 12 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class TestOther : public TestFixture {
TEST_CASE(moveAndReference);
TEST_CASE(moveForRange);
TEST_CASE(moveTernary);
TEST_CASE(movePointerAlias);

TEST_CASE(funcArgNamesDifferent);
TEST_CASE(funcArgOrderDifferent);
Expand Down Expand Up @@ -12114,6 +12115,17 @@ class TestOther : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void movePointerAlias()
{
check("void f() {\n"
" std::string s;\n"
" std::string s1 = std::move(s);\n"
" const std::string* s_p = &s;\n"
" s_p->size();\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (warning) Access of moved variable '.'.\n", errout_str());
}

void funcArgNamesDifferent() {
check("void func1(int a, int b, int c);\n"
"void func1(int a, int b, int c) { }\n"
Expand Down
2 changes: 1 addition & 1 deletion test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6161,7 +6161,7 @@ class TestUninitVar : public TestFixture {
" A* p = &a;\n"
" g(p->x);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:8]: (error) Uninitialized variable: p->x\n", errout_str());
ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: p->x\n", errout_str());

valueFlowUninit("void f() {\n"
" int a;\n"
Expand Down
Loading