Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -3370,7 +3370,7 @@ bool isConstVarExpression(const Token *tok, const std::function<bool(const Token
if (!tok)
return false;
if (tok->str() == "?" && 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 ("))
Expand Down
12 changes: 12 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading