From 3d965b5b81fa4dd6cf830a937d35bad2b7e99e2c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 20 Mar 2023 19:29:49 +0100 Subject: [PATCH] Fix #11618 FP functionConst with call to static function (#4898) --- lib/checkclass.cpp | 2 +- test/testclass.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2b92058b0..bc437300a 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2313,7 +2313,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool& mayModifyArgs = false; for (nonneg int argIndex = 0; argIndex < argMax; ++argIndex) { const Variable* const argVar = f->getArgumentVar(argIndex); - if (!argVar || !argVar->valueType() || ((argVar->valueType()->pointer || argVar->valueType()->reference != Reference::None) && !argVar->isConst())) { + if (!argVar || ((argVar->isArrayOrPointer() || argVar->isReference()) && !argVar->isConst())) { mayModifyArgs = true; break; } diff --git a/test/testclass.cpp b/test/testclass.cpp index 7d6ce802c..2c3935d3f 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -197,6 +197,7 @@ private: TEST_CASE(const81); // ticket #11330 TEST_CASE(const82); // ticket #11513 TEST_CASE(const83); + TEST_CASE(const84); TEST_CASE(const_handleDefaultParameters); TEST_CASE(const_passThisToMemberOfOtherClass); @@ -6360,6 +6361,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void const84() { // #11618 + checkConst("struct S {\n" + " int a[2], b[2];\n" + " void f() { f(a, b); }\n" + " static void f(const int p[2], int q[2]);\n" + "};\n" + "void S::f(const int p[2], int q[2]) {\n" + " q[0] = p[0];\n" + " q[1] = p[1];\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void const_handleDefaultParameters() { checkConst("struct Foo {\n" " void foo1(int i, int j = 0) {\n"