diff --git a/lib/astutils.cpp b/lib/astutils.cpp index a08d86a2f86..a077beac725 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 e221accc782..e867490e45d 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2053,7 +2053,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 085b39cfffb..5a26c222532 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" @@ -5096,6 +5098,14 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:3:8]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:3:8]: (style) Parameter 'q' 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() {