diff --git a/cfg/std.cfg b/cfg/std.cfg index 033fc15d2d6..8af1b446802 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -8831,7 +8831,23 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init 0: - + + + + false + + + + + + + + false + + + + + false @@ -8839,7 +8855,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init - + false diff --git a/lib/astutils.cpp b/lib/astutils.cpp index e2e19b6bd91..1b1f1fa66e5 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2794,7 +2794,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, const Token * ptok = tok2; while (Token::Match(ptok->astParent(), ".|::")) ptok = ptok->astParent(); - int pindirect = indirect; + int pindirect = std::max(indirect - derefs, 0); if (indirect == 0 && astIsLHS(tok2) && Token::Match(ptok, ". %var%") && astIsPointer(ptok->next())) pindirect = 1; bool inconclusive = false; diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index cf4f74b6dbf..fb37d4a2957 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -5120,6 +5120,11 @@ int f_constVariable_std_begin() { return arr[0]; } +void f_constParameterPointer_std_begin(std::vector* p) { + std::fill(std::begin(*p), std::end(*p), 0); +} + + std::size_t uninitvar_std_size() { // #14976 int a[3]; return std::size(a); diff --git a/test/testother.cpp b/test/testother.cpp index 085b39cfffb..df0b657eac1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5096,6 +5096,11 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:3:8]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:3:8]: (style) Parameter 'q' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + + check("void f(std::vector& v, int* p) {\n" // #15203 + " v.push_back(*p);\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:1:34]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); } void constArray() { @@ -10509,6 +10514,14 @@ class TestOther : public TestFixture { " return m.trace();\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("std::string f(const std::string& s) {\n" + " std::string u = s;\n" + " std::string::iterator i = u.begin();\n" + " *i = toupper(*i);\n" + " return u;\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void checkNegativeShift() {