diff --git a/lib/astutils.cpp b/lib/astutils.cpp index b8e86b3e29d..34f8a73ddd1 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; @@ -3370,7 +3370,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 (")) diff --git a/test/testother.cpp b/test/testother.cpp index 241a7512000..63a58b226d6 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4775,6 +4775,18 @@ class TestOther : public TestFixture { " strcpy(r.c, p->c_str());\n" "}\n"); ASSERT_EQUALS("[test.cpp:7:21]: (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() {