From 13e6df3f7ecb9576c5ff5c225a1cd533cf62e6dd Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 11 Nov 2026 09:07:49 +0100 Subject: [PATCH 1/6] Update astutils.cpp --- lib/astutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index e2e19b6bd91..0f253930248 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 = indirect - derefs; if (indirect == 0 && astIsLHS(tok2) && Token::Match(ptok, ". %var%") && astIsPointer(ptok->next())) pindirect = 1; bool inconclusive = false; From 63dda398dfd08762f9210c337664fd18f8765203 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 11 Nov 2026 09:08:44 +0100 Subject: [PATCH 2/6] Update testother.cpp --- test/testother.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index adfc2ff0f2a..c58aef2650e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5086,6 +5086,11 @@ class TestOther : public TestFixture { "void g(__attribute__((unused)) int *p) {}\n" "void h(int *p) {}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (style) Parameter 'p' 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() { From 356445d3f195a0277a04d381e6cea99b8961a0fa Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sat, 21 Nov 2026 13:14:36 +0100 Subject: [PATCH 3/6] Fix --- lib/astutils.cpp | 2 +- test/testother.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 0f253930248..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 - derefs; + 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/testother.cpp b/test/testother.cpp index ac6f242a91c..8dd42322b23 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -10514,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() { From a3ddba5531b5a95f7af9998227343b5de5ee2153 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sat, 21 Nov 2026 13:21:02 +0100 Subject: [PATCH 4/6] Format --- test/testother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testother.cpp b/test/testother.cpp index 8dd42322b23..df0b657eac1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -10518,7 +10518,7 @@ class TestOther : public TestFixture { 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" + " *i = toupper(*i);\n" " return u;\n" "}\n"); ASSERT_EQUALS("", errout_str()); From dc123e53e607256e30e1208e52ee82a6e426bab8 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sun, 22 Nov 2026 10:56:37 +0100 Subject: [PATCH 5/6] Fix --- cfg/std.cfg | 20 ++++++++++++++++++-- test/cfg/std.cpp | 5 +++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index 033fc15d2d6..8a05c67386d 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/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); From d16a499e2c546f4a32016a9a06112a67d2947223 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sun, 22 Nov 2026 11:09:55 +0100 Subject: [PATCH 6/6] Fix --- cfg/std.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index 8a05c67386d..8af1b446802 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -8855,7 +8855,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init - + false