Skip to content

Commit 9682731

Browse files
Fix #14700 FN constParameterPointer with usage in ternary (#8503)
1 parent ba55280 commit 9682731

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

lib/checkother.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,10 @@ void CheckOther::checkConstPointer()
19471947
continue;
19481948
if (mSettings->library.isFunctionConst(parent->astOperand2()))
19491949
continue;
1950+
if (parent->astOperand2()->varId()) {
1951+
if (gparent->str() == "?" && astIsLHS(parent))
1952+
continue;
1953+
}
19501954
}
19511955
}
19521956
if (hasIncDecPlus) {

test/testother.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4817,6 +4817,12 @@ class TestOther : public TestFixture {
48174817
" return bar = 0;\n"
48184818
"}\n");
48194819
ASSERT_EQUALS("", errout_str());
4820+
4821+
check("struct S { int x; };\n" // #14700
4822+
"int f(S* s) {\n"
4823+
" return s->x ? 1 : 0;\n"
4824+
"}\n");
4825+
ASSERT_EQUALS("[test.cpp:2:10]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str());
48204826
}
48214827

48224828
void constArray() {

0 commit comments

Comments
 (0)