Skip to content

Commit e06e98f

Browse files
Fix #14559 FN constVariablePointer (ternary expression passed to unknown function, regression) (danmar#8331)
1 parent 38a45b4 commit e06e98f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/astutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,7 +2628,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings,
26282628
if (!tok->isMutableExpr())
26292629
return false;
26302630

2631-
if (indirect == 0 && isConstVarExpression(tok))
2631+
if (isConstVarExpression(tok))
26322632
return false;
26332633

26342634
const Token *tok2 = tok;
@@ -3370,7 +3370,7 @@ bool isConstVarExpression(const Token *tok, const std::function<bool(const Token
33703370
if (!tok)
33713371
return false;
33723372
if (tok->str() == "?" && tok->astOperand2() && tok->astOperand2()->str() == ":") // ternary operator
3373-
return isConstVarExpression(tok->astOperand2()->astOperand1()) && isConstVarExpression(tok->astOperand2()->astOperand2()); // left and right of ":"
3373+
return isConstVarExpression(tok->astOperand2()->astOperand1()) || isConstVarExpression(tok->astOperand2()->astOperand2()); // left and right of ":"
33743374
if (skipPredicate && skipPredicate(tok))
33753375
return false;
33763376
if (Token::simpleMatch(tok->previous(), "sizeof ("))

test/testother.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4775,6 +4775,18 @@ class TestOther : public TestFixture {
47754775
" strcpy(r.c, p->c_str());\n"
47764776
"}\n");
47774777
ASSERT_EQUALS("[test.cpp:7:21]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str());
4778+
4779+
check("struct S {\n" // #14559
4780+
" int gc() const;\n"
4781+
" int gnc();\n"
4782+
"};\n"
4783+
"int f1(S* s) {\n"
4784+
" return h(s ? s->gc() : 1);\n"
4785+
"}\n"
4786+
"int f2(S* s) {\n"
4787+
" return h(s ? s->gnc() : 1);\n"
4788+
"}\n");
4789+
ASSERT_EQUALS("[test.cpp:5:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str());
47784790
}
47794791

47804792
void constArray() {

0 commit comments

Comments
 (0)