File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 4747#include < set>
4848#include < type_traits>
4949
50+ static bool isDereferenceOp (const Token* tok)
51+ {
52+ if (!tok)
53+ return false ;
54+ if (!tok->astOperand1 ())
55+ return false ;
56+ if (tok->str () == " *" )
57+ return true ;
58+ return tok->str () == " ." && tok->originalName () == " ->" ;
59+ }
60+
5061struct ValueFlowAnalyzer : Analyzer {
5162 const Settings& settings;
5263 ProgramMemoryState pms;
@@ -586,7 +597,7 @@ struct ValueFlowAnalyzer : Analyzer {
586597 } else {
587598 return analyzeMatch (tok, d) | Action::Match;
588599 }
589- } else if (ref-> isUnaryOp ( " * " ) && !match (ref->astOperand1 ())) {
600+ } else if (isDereferenceOp (ref ) && !match (ref->astOperand1 ())) {
590601 const Token* lifeTok = nullptr ;
591602 for (const ValueFlow::Value& v:ref->astOperand1 ()->values ()) {
592603 if (!v.isLocalLifetimeValue ())
Original file line number Diff line number Diff line change @@ -277,6 +277,7 @@ class TestOther : public TestFixture {
277277 TEST_CASE (moveAndReference);
278278 TEST_CASE (moveForRange);
279279 TEST_CASE (moveTernary);
280+ TEST_CASE (movePointerAlias);
280281
281282 TEST_CASE (funcArgNamesDifferent);
282283 TEST_CASE (funcArgOrderDifferent);
@@ -12111,6 +12112,17 @@ class TestOther : public TestFixture {
1211112112 ASSERT_EQUALS (" " , errout_str ());
1211212113 }
1211312114
12115+ void movePointerAlias ()
12116+ {
12117+ check (" void f() {\n "
12118+ " std::string s;\n "
12119+ " std::string s1 = std::move(s);\n "
12120+ " const std::string* s_p = &s;\n "
12121+ " s_p->size();\n "
12122+ " }\n " );
12123+ ASSERT_EQUALS (" [test.cpp:5]: (warning) Access of moved variable '.'.\n " , errout_str ());
12124+ }
12125+
1211412126 void funcArgNamesDifferent () {
1211512127 check (" void func1(int a, int b, int c);\n "
1211612128 " void func1(int a, int b, int c) { }\n "
Original file line number Diff line number Diff line change @@ -6161,7 +6161,7 @@ class TestUninitVar : public TestFixture {
61616161 " A* p = &a;\n "
61626162 " g(p->x);\n "
61636163 " }\n " );
6164- ASSERT_EQUALS (" [test.cpp:7] -> [test.cpp: 8]: (error) Uninitialized variable: p->x\n " , errout_str ());
6164+ ASSERT_EQUALS (" [test.cpp:8]: (error) Uninitialized variable: p->x\n " , errout_str ());
61656165
61666166 valueFlowUninit (" void f() {\n "
61676167 " int a;\n "
You can’t perform that action at this time.
0 commit comments