From 0ba883f64bbb52299a40c5f8844dbce8d373e07c Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 27 Nov 2026 19:34:33 +0100 Subject: [PATCH] Fix #15226 --- lib/astutils.cpp | 2 +- lib/checkother.cpp | 2 +- test/testother.cpp | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index e2e19b6bd91..ff677bd225a 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2369,7 +2369,7 @@ static T* getTokenArgumentFunctionImpl(T* tok, int& argn) parent = parent->astParent(); while (parent && parent->isCast()) parent = parent->astParent(); - if (Token::Match(parent, "[+-]") && parent->valueType() && parent->valueType()->pointer) + if (Token::Match(parent, "[+-]") && (!parent->valueType() || parent->valueType()->pointer)) parent = parent->astParent(); // passing variable to subfunction? diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 79697a2e6d7..c931b1e30d4 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2063,7 +2063,7 @@ void CheckOtherImpl::checkConstPointer() int argn = -1; if (Token::simpleMatch(gparent, "return")) { const Function* function = getEnclosingFunction(var); - if (function && (!Function::returnsReference(function) || Function::returnsConst(function))) + if (function && (!Function::returnsReference(function, /*unknown*/ true) || Function::returnsConst(function))) continue; } else if (Token::Match(gparent, "%assign%") && parent == gparent->astOperand2()) { diff --git a/test/testother.cpp b/test/testother.cpp index d6025e9a640..7b3850e452d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4966,7 +4966,9 @@ class TestOther : public TestFixture { " int i = 0;\n" " return [](int* p) { return *p; }(&i);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3:20]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:3:20]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", + "", + errout_str()); check("struct S {\n" // #14571 " char* c;\n" @@ -5087,6 +5089,14 @@ class TestOther : public TestFixture { "void g(__attribute__((unused)) int *p) {}\n" "void h(int *p) {}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + + check("void f(int* p, U n) {\n" // #15226 + " g(*(p + n));\n" + "}\n" + "U g(int* p, int n) {\n" + " return *(p + n);\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void constArray() {