From 85ee7007cbcf219ca78bb39d5b01f4e2daea1cb6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 16 Nov 2026 07:57:15 +0100 Subject: [PATCH 1/5] Update testother.cpp --- test/testother.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index d6025e9a640..d7af1dce7db 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5087,6 +5087,12 @@ 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("int* f(int* s) {\n" // #15219 + " int* q = s - 1;\n" + " return q;\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void constArray() { From a5d70b1eec96f6077d2ead9099e2aa86b5e19cbd Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 16 Nov 2026 07:58:05 +0100 Subject: [PATCH 2/5] Update checkother.cpp --- lib/checkother.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 79697a2e6d7..3e406223ccf 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2089,7 +2089,9 @@ void CheckOtherImpl::checkConstPointer() } } else { int argn = -1; - if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-|<<|;")) + if (Token::Match(parent, "%oror%|%comp%|&&|?|-|!|<<|;")) + continue; + if (Token::simpleMatch(parent, "-") && parent->valueType() && parent->valueType()->pointer == 0) continue; if (hasIncDecPlus && (!parent->astParent() || parent->astParent()->str() == ";")) continue; From 77ceb53a9ebcaded784899239bd1bbe07e13457b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 16 Nov 2026 07:59:34 +0100 Subject: [PATCH 3/5] Update checkother.cpp --- lib/checkother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 3e406223ccf..604f759e793 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2089,7 +2089,7 @@ void CheckOtherImpl::checkConstPointer() } } else { int argn = -1; - if (Token::Match(parent, "%oror%|%comp%|&&|?|-|!|<<|;")) + if (Token::Match(parent, "%oror%|%comp%|&&|?|!|<<|;")) continue; if (Token::simpleMatch(parent, "-") && parent->valueType() && parent->valueType()->pointer == 0) continue; From a236dc8a7f52665d925d2aa4f64a4d98bc4d442f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 17 Nov 2026 07:59:26 +0100 Subject: [PATCH 4/5] Update checkother.cpp [skip ci] --- lib/checkother.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 604f759e793..ea9c881876b 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2017,8 +2017,8 @@ void CheckOtherImpl::checkConstPointer() pointers.emplace(var); const Token* parent = tok->astParent(); enum Deref : std::uint8_t { NONE, DEREF, MEMBER } deref = NONE; - bool hasIncDecPlus = false; - if (parent && (parent->isUnaryOp("*") || (((hasIncDecPlus = parent->isIncDecOp()) || (hasIncDecPlus = (parent->str() == "+"))) && + bool hasIncDecPlusMinus = false; + if (parent && (parent->isUnaryOp("*") || (((hasIncDecPlusMinus = parent->isIncDecOp()) || (hasIncDecPlusMinus = Token::Match(parent, "[+-]"))) && parent->astParent() && parent->astParent()->isUnaryOp("*")))) deref = DEREF; else if (Token::simpleMatch(parent, "[") && parent->astOperand1() == tok && tok != nameTok) @@ -2054,7 +2054,7 @@ void CheckOtherImpl::checkConstPointer() } } } - if (hasIncDecPlus) { + if (hasIncDecPlusMinus) { parent = gparent; gparent = gparent ? gparent->astParent() : nullptr; } @@ -2093,7 +2093,7 @@ void CheckOtherImpl::checkConstPointer() continue; if (Token::simpleMatch(parent, "-") && parent->valueType() && parent->valueType()->pointer == 0) continue; - if (hasIncDecPlus && (!parent->astParent() || parent->astParent()->str() == ";")) + if (hasIncDecPlusMinus && (!parent->astParent() || parent->astParent()->str() == ";")) continue; if (Token::simpleMatch(parent, "(") && Token::Match(parent->astOperand1(), "if|while")) continue; From 5db5d7f30982325da05350e5d229520af2c0482a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:00:29 +0100 Subject: [PATCH 5/5] Update testother.cpp --- test/testother.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/testother.cpp b/test/testother.cpp index d7af1dce7db..27659086416 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5091,8 +5091,11 @@ class TestOther : public TestFixture { check("int* f(int* s) {\n" // #15219 " int* q = s - 1;\n" " return q;\n" + "}\n" + "int g(int* p) {\n" + " return *(p - 1);\n" "}\n"); - ASSERT_EQUALS("", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); } void constArray() {