diff --git a/cfg/std.cfg b/cfg/std.cfg index 311f9bae3..ede343a4b 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -8586,7 +8586,6 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init false - diff --git a/lib/astutils.cpp b/lib/astutils.cpp index cf5f228e1..20305a7d3 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2531,7 +2531,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, return false; } } - if (settings && settings->library.isFunctionConst(ftok)) + if ((settings && settings->library.isFunctionConst(ftok)) || (astIsSmartPointer(tok) && ftok->str() == "get")) // TODO: replace with action/yield? return false; const Function * fun = ftok->function(); diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 1caf7ebf3..cf26f73cb 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -4724,6 +4724,14 @@ void smartPtr_get() *p = 1; } +void smartPtr_get2(std::vector>& v) +{ + for (auto& u : v) { + int* p = u.get(); + *p = 0; + } +} + void smartPtr_reset() { std::unique_ptr p(new int()); diff --git a/test/testclass.cpp b/test/testclass.cpp index 4119f8e2f..93d85a623 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -6532,7 +6532,7 @@ private: errout.str()); checkConst("struct S {\n" - " bool f() { return p.get() != nullptr; }\n" + " bool f() { return p != nullptr; }\n" " std::shared_ptr p;\n" "};\n"); ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Technically the member function 'S::f' can be const.\n",