From dada503afcd3b36e71f0781a2bffc75c6f34eac6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 5 Nov 2026 13:54:52 +0100 Subject: [PATCH 01/14] Update vf_analyzers.cpp --- lib/vf_analyzers.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/vf_analyzers.cpp b/lib/vf_analyzers.cpp index 27c27934f31..ec54b8efde0 100644 --- a/lib/vf_analyzers.cpp +++ b/lib/vf_analyzers.cpp @@ -228,7 +228,8 @@ struct ValueFlowAnalyzer : Analyzer { if (inconclusive) return Action::Read | Action::Inconclusive; if (isVariableChanged(tok, getIndirect(tok), getSettings())) { - if (Token::Match(tok->astParent(), "*|[|.|++|--")) + if (Token::Match(tok->astParent(), "*|[|.|++|--") || + (tok->astParent() && tok->astParent()->isAssignmentOp() && tok->astParent()->str().size() == 2)) // compound assignment return Action::Read | Action::Invalid; // Check if its assigned to the same value if (value && !value->isImpossible() && Token::simpleMatch(tok->astParent(), "=") && astIsLHS(tok) && From 30484de423b3a99b622eec52296d6853203273bd Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 5 Nov 2026 13:55:41 +0100 Subject: [PATCH 02/14] Update testnullpointer.cpp --- test/testnullpointer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index ca5c183c911..111e04c35f6 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -4707,7 +4707,7 @@ class TestNullPointer : public TestFixture { " p += a;\n" " *p = 0;\n" "}\n"); - ASSERT_EQUALS("", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str()); check("int f(int *p = 0) {\n" " if (p == 0) {\n" From 58126147d4cc2152fd0934d6c8863a4f9ca22b55 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 5 Nov 2026 13:56:26 +0100 Subject: [PATCH 03/14] Update testvalueflow.cpp --- test/testvalueflow.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 3609bf2aee2..392c5cef551 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1110,6 +1110,12 @@ class TestValueFlow : public TestFixture { " g(std::move(x)).f(1);\n" "}\n"; ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MoveKind::MovedVariable)); + + code = "void f(std::string x) {\n" // #15155 + " std::string a{ std::move(x) };\n" + " x += \"abc\";\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfX(code, 3U, ValueFlow::Value::MoveKind::MovedVariable)); } void valueFlowCalculations() { From bbbd6e51a1c266fbfc42552c25049d070839775e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:17:13 +0100 Subject: [PATCH 04/14] Update vf_analyzers.cpp [skip ci] --- lib/vf_analyzers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vf_analyzers.cpp b/lib/vf_analyzers.cpp index ec54b8efde0..b3e692be891 100644 --- a/lib/vf_analyzers.cpp +++ b/lib/vf_analyzers.cpp @@ -229,7 +229,7 @@ struct ValueFlowAnalyzer : Analyzer { return Action::Read | Action::Inconclusive; if (isVariableChanged(tok, getIndirect(tok), getSettings())) { if (Token::Match(tok->astParent(), "*|[|.|++|--") || - (tok->astParent() && tok->astParent()->isAssignmentOp() && tok->astParent()->str().size() == 2)) // compound assignment + (Token::Match(tok->astParent(), "%assign%") && tok->astParent()->str().size() > 1)) // compound assignment return Action::Read | Action::Invalid; // Check if its assigned to the same value if (value && !value->isImpossible() && Token::simpleMatch(tok->astParent(), "=") && astIsLHS(tok) && From 28c5e6587c5c8c300212ff96676e27690cb70ebd Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:18:14 +0100 Subject: [PATCH 05/14] Update testuninitvar.cpp [skip ci] --- test/testuninitvar.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 4d1a913ed3a..31581ce62a2 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -6846,6 +6846,15 @@ class TestUninitVar : public TestFixture { " return a[0];\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + valueFlowUninit("void f(int i) {\n" + " int x, y;\n" + " x += i;\n" + " y <<= i;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Uninitialized variable: x [uninitvar]\n" + "[test.cpp:4:5]: (error) Uninitialized variable: y [uninitvar]\n", + errout_str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value From 811a54c90d710e1e6afdd83ec136640218b3e273 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:19:25 +0100 Subject: [PATCH 06/14] Update testvalueflow.cpp --- test/testvalueflow.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 392c5cef551..7ec73a4868f 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1116,6 +1116,16 @@ class TestValueFlow : public TestFixture { " x += \"abc\";\n" "}\n"; ASSERT_EQUALS(true, testValueOfX(code, 3U, ValueFlow::Value::MoveKind::MovedVariable)); + + code = "struct S {\n" + " S& operator<<=(int i);\n" + " std::string m;\n" + "};\n" + "void f(S x) {\n" + " S a{ std::move(x) };\n" + " x <<= 5;\n" + "}"; + ASSERT_EQUALS(true, testValueOfX(code, 7U, ValueFlow::Value::MoveKind::MovedVariable)); } void valueFlowCalculations() { From 5ecbfde8986f172588eabd568b1e337ad75bbae1 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 13 Nov 2026 22:56:00 +0100 Subject: [PATCH 07/14] Fix --- lib/astutils.cpp | 2 +- test/testother.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index e2e19b6bd91..44ca89d02f5 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2688,7 +2688,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, }; tok2 = skipRedundantPtrOp(tok2, tok2->astParent()); - if (tok2->astParent() && tok2->astParent()->isAssignmentOp()) { + if (tok2->astParent() && tok2->astParent()->isAssignmentOp() && (indirect == 0 || tok2->astParent()->str() == "=")) { if (astIsLHS(tok2)) return true; // Check if assigning to a non-const lvalue diff --git a/test/testother.cpp b/test/testother.cpp index a194c297a8b..4130a7e4178 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5039,6 +5039,17 @@ class TestOther : public TestFixture { "};\n"); ASSERT_EQUALS("[test.cpp:2:17]: (style) Either there is a missing override/final keyword, or the parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + + check("void f(int *r, int s, int N) {\n" + " int *p = nullptr;\n" + " for (int j = 0; j < N; j++) {\n" + " if (p) {}\n" + " p = r;\n" + " r += s;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2:10]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\n", + errout_str()); } void constArray() { From 6edbf5f84b8db88b0e4ade40c5791b1b90d940ab Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sun, 15 Nov 2026 14:25:12 +0100 Subject: [PATCH 08/14] Fix --- lib/astutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 44ca89d02f5..f80ec4676ec 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2688,7 +2688,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, }; tok2 = skipRedundantPtrOp(tok2, tok2->astParent()); - if (tok2->astParent() && tok2->astParent()->isAssignmentOp() && (indirect == 0 || tok2->astParent()->str() == "=")) { + if (tok2->astParent() && tok2->astParent()->isAssignmentOp() && (indirect - derefs == 0 || tok2->astParent()->str() == "=")) { if (astIsLHS(tok2)) return true; // Check if assigning to a non-const lvalue From c0eacdf8b13559f96a425a8066483e53b2f2c451 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Mon, 16 Nov 2026 18:52:07 +0100 Subject: [PATCH 09/14] Undo --- lib/astutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index f80ec4676ec..44ca89d02f5 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2688,7 +2688,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, }; tok2 = skipRedundantPtrOp(tok2, tok2->astParent()); - if (tok2->astParent() && tok2->astParent()->isAssignmentOp() && (indirect - derefs == 0 || tok2->astParent()->str() == "=")) { + if (tok2->astParent() && tok2->astParent()->isAssignmentOp() && (indirect == 0 || tok2->astParent()->str() == "=")) { if (astIsLHS(tok2)) return true; // Check if assigning to a non-const lvalue From 8de381be82abe71a9368f733ddb279793118825e Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Mon, 16 Nov 2026 19:35:53 +0100 Subject: [PATCH 10/14] Fix --- lib/astutils.cpp | 6 ++++-- test/testother.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 44ca89d02f5..c5fca7407e6 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2646,7 +2646,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, return false; const Token *tok2 = tok; - int derefs = 0; + int derefs = 0, arrayAccess = 0; while ((tok2->astParent() && tok2->astParent()->isUnaryOp("*")) || (Token::simpleMatch(tok2->astParent(), ".") && !Token::Match(tok2->astParent()->astParent(), "[(,]")) || (tok2->astParent() && tok2->astParent()->isUnaryOp("&") && Token::simpleMatch(tok2->astParent()->astParent(), ".") && tok2->astParent()->astParent()->originalName()=="->") || @@ -2654,6 +2654,8 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, (Token::simpleMatch(tok2->astParent(), "(") && tok2->astParent()->isCast())) { if (tok2->astParent() && (tok2->astParent()->isUnaryOp("*") || (astIsLHS(tok2) && tok2->astParent()->originalName() == "->" && !hasOverloadedMemberAccess(tok2)))) derefs++; + if (Token::simpleMatch(tok2->astParent(), "[") && tok2->valueType() && tok2->valueType()->pointer > 0) + arrayAccess++; if (derefs > indirect) break; if (tok2->astParent() && tok2->astParent()->isUnaryOp("&") && Token::simpleMatch(tok2->astParent()->astParent(), ".") && tok2->astParent()->astParent()->originalName()=="->") @@ -2688,7 +2690,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, }; tok2 = skipRedundantPtrOp(tok2, tok2->astParent()); - if (tok2->astParent() && tok2->astParent()->isAssignmentOp() && (indirect == 0 || tok2->astParent()->str() == "=")) { + if (tok2->astParent() && tok2->astParent()->isAssignmentOp() && (indirect - derefs - arrayAccess == 0 || tok2->astParent()->str() == "=")) { if (astIsLHS(tok2)) return true; // Check if assigning to a non-const lvalue diff --git a/test/testother.cpp b/test/testother.cpp index 453644da4ec..53947e6d9a8 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4300,6 +4300,12 @@ class TestOther : public TestFixture { "}\n"); ASSERT_EQUALS("[test.cpp:3:7]: (style) Variable 'a' can be declared as const array [constVariable]\n", errout_str()); + + check("void f(std::vector& v) {\n" + " int *p = v.data();\n" + " p[0] += 1;\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void constParameterCallback() { From c3ca0d752925a1825b8437fef37704cf3338b03d Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Mon, 16 Nov 2026 19:39:26 +0100 Subject: [PATCH 11/14] Format --- test/testother.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/testother.cpp b/test/testother.cpp index 53947e6d9a8..e7c018f8b00 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4302,8 +4302,8 @@ class TestOther : public TestFixture { errout_str()); check("void f(std::vector& v) {\n" - " int *p = v.data();\n" - " p[0] += 1;\n" + " int *p = v.data();\n" + " p[0] += 1;\n" "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -14090,7 +14090,7 @@ class TestOther : public TestFixture { void unusedVariableValueTemplate() { check("#include \n" "class A\n" - "{\n" + "{\n"s "public:\n" " class Hash\n" " {\n" From 6240b7519435f1922db81f5baf2d7d66ab3b059e Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Mon, 16 Nov 2026 19:51:46 +0100 Subject: [PATCH 12/14] Undo --- test/testother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testother.cpp b/test/testother.cpp index e7c018f8b00..dff51d15743 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -14090,7 +14090,7 @@ class TestOther : public TestFixture { void unusedVariableValueTemplate() { check("#include \n" "class A\n" - "{\n"s + "{\n" "public:\n" " class Hash\n" " {\n" From 1271964a4ffda05638b1358c8a064d90eb41a9ae Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:22:08 +0100 Subject: [PATCH 13/14] Update astutils.cpp [skip ci] --- lib/astutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index c5fca7407e6..9d84b3bffa8 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2690,7 +2690,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, }; tok2 = skipRedundantPtrOp(tok2, tok2->astParent()); - if (tok2->astParent() && tok2->astParent()->isAssignmentOp() && (indirect - derefs - arrayAccess == 0 || tok2->astParent()->str() == "=")) { + if (tok2->astParent() && tok2->astParent()->isAssignmentOp() && (indirect - derefs - arrayAccess <= 0 || tok2->astParent()->str() == "=")) { if (astIsLHS(tok2)) return true; // Check if assigning to a non-const lvalue From 0ea5f5f44f6e92b56b87b02e7b23cf2dc4104bc3 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:24:34 +0100 Subject: [PATCH 14/14] Update testother.cpp --- test/testother.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index dff51d15743..38be9a6d7d7 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4304,6 +4304,14 @@ class TestOther : public TestFixture { check("void f(std::vector& v) {\n" " int *p = v.data();\n" " p[0] += 1;\n" + "}\n" + "void g(std::vector& v) {\n" + " int** p = v.data();\n" + " p[0][0] += 1;\n" + "}\n" + "void h(std::vector& v) {\n" + " int** p = v.data();\n" + " *p[0] += 1;\n" "}\n"); ASSERT_EQUALS("", errout_str()); }