Skip to content

Commit b2800b4

Browse files
committed
Fix #14748 FN constParameterPointer (dereference in ternary)
1 parent 89da2d1 commit b2800b4

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/checkother.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,8 @@ void CheckOther::checkConstPointer()
19391939
const Token* gparent = parent->astParent();
19401940
while (Token::simpleMatch(gparent, "[") && parent != gparent->astOperand2() && parent->str() == gparent->str())
19411941
gparent = gparent->astParent();
1942+
while (Token::Match(gparent, "[?:]"))
1943+
gparent = gparent->astParent();
19421944
if (deref == MEMBER) {
19431945
if (!gparent)
19441946
continue;

test/testother.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4823,6 +4823,20 @@ class TestOther : public TestFixture {
48234823
" return s->x ? 1 : 0;\n"
48244824
"}\n");
48254825
ASSERT_EQUALS("[test.cpp:2:10]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str());
4826+
4827+
check("int f(int *p, int *q) {\n" // #14748
4828+
" return p ? *p : *q;\n"
4829+
"}\n"
4830+
"void g(int *p, int *q) {\n"
4831+
" int& r = p ? *p : *q;\n"
4832+
" r = 0;\n"
4833+
"}\n"
4834+
"void h(int *p, int *q) {\n"
4835+
" i(p ? *p : *q);\n"
4836+
"}\n");
4837+
ASSERT_EQUALS("[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n"
4838+
"[test.cpp:1:20]: (style) Parameter 'q' can be declared as pointer to const [constParameterPointer]\n",
4839+
errout_str());
48264840
}
48274841

48284842
void constArray() {

0 commit comments

Comments
 (0)