From d75f8dca4c975adf2f35c1534e5b07607a446169 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 12 Mar 2026 13:56:34 +0100 Subject: [PATCH 1/2] Update astutils.cpp --- lib/astutils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 2d53ef0b0c1..c718b78f6e3 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2628,7 +2628,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, if (!tok->isMutableExpr()) return false; - if (indirect == 0 && isConstVarExpression(tok)) + if (isConstVarExpression(tok)) return false; const Token *tok2 = tok; @@ -3369,7 +3369,7 @@ bool isConstVarExpression(const Token *tok, const std::functionstr() == "?" && tok->astOperand2() && tok->astOperand2()->str() == ":") // ternary operator - return isConstVarExpression(tok->astOperand2()->astOperand1()) && isConstVarExpression(tok->astOperand2()->astOperand2()); // left and right of ":" + return isConstVarExpression(tok->astOperand2()->astOperand1()) || isConstVarExpression(tok->astOperand2()->astOperand2()); // left and right of ":" if (skipPredicate && skipPredicate(tok)) return false; if (Token::simpleMatch(tok->previous(), "sizeof (")) From 1e0577866fab10f9e5b040e0bf9a7c2cbce8edd4 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 12 Mar 2026 14:14:17 +0100 Subject: [PATCH 2/2] Update testother.cpp --- test/testother.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 88c83eba4b1..6426ad86370 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4763,6 +4763,18 @@ class TestOther : public TestFixture { " return [](int* p) { return *p; }(&i);\n" "}\n"); ASSERT_EQUALS("[test.cpp:3:20]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + + check("struct S {\n" // #14559 + " int gc() const;\n" + " int gnc();\n" + "};\n" + "int f1(S* s) {\n" + " return h(s ? s->gc() : 1);\n" + "}\n" + "int f2(S* s) {\n" + " return h(s ? s->gnc() : 1);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:5:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str()); } void constArray() {