From b2800b4ac359f73e283a187374a483779bf19096 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Tue, 12 May 2026 19:20:57 +0200 Subject: [PATCH 1/3] Fix #14748 FN constParameterPointer (dereference in ternary) --- lib/checkother.cpp | 2 ++ test/testother.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index fd23e113509..89242808413 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1939,6 +1939,8 @@ void CheckOther::checkConstPointer() const Token* gparent = parent->astParent(); while (Token::simpleMatch(gparent, "[") && parent != gparent->astOperand2() && parent->str() == gparent->str()) gparent = gparent->astParent(); + while (Token::Match(gparent, "[?:]")) + gparent = gparent->astParent(); if (deref == MEMBER) { if (!gparent) continue; diff --git a/test/testother.cpp b/test/testother.cpp index c23e8c64155..57257dcca15 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4823,6 +4823,20 @@ class TestOther : public TestFixture { " return s->x ? 1 : 0;\n" "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + + check("int f(int *p, int *q) {\n" // #14748 + " return p ? *p : *q;\n" + "}\n" + "void g(int *p, int *q) {\n" + " int& r = p ? *p : *q;\n" + " r = 0;\n" + "}\n" + "void h(int *p, int *q) {\n" + " i(p ? *p : *q);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:1:20]: (style) Parameter 'q' can be declared as pointer to const [constParameterPointer]\n", + errout_str()); } void constArray() { From dbae23c8233f8b234e61015611c145246b1ab2ea Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 13 May 2026 08:35:26 +0200 Subject: [PATCH 2/3] Update checkother.cpp [skip ci] --- lib/checkother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 89242808413..5127fb6b0b9 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1937,7 +1937,7 @@ void CheckOther::checkConstPointer() continue; if (deref != NONE) { const Token* gparent = parent->astParent(); - while (Token::simpleMatch(gparent, "[") && parent != gparent->astOperand2() && parent->str() == gparent->str()) + while (Token::simpleMatch(gparent, "[") && parent != gparent->astOperand2()) gparent = gparent->astParent(); while (Token::Match(gparent, "[?:]")) gparent = gparent->astParent(); From d40935cb03daacf378755f4498651a0883d25c21 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 13 May 2026 08:36:49 +0200 Subject: [PATCH 3/3] Update testother.cpp --- test/testother.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 57257dcca15..64693ef53e4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4824,6 +4824,12 @@ class TestOther : public TestFixture { "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + check("struct S { int a[1][1]; };\n" // #14714 + "int f(S* s) {\n" + " return s->a[0][0] ? 1 : 0;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2:10]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + check("int f(int *p, int *q) {\n" // #14748 " return p ? *p : *q;\n" "}\n"