Fix #11618 FP functionConst with call to static function (#4898)

This commit is contained in:
chrchr-github 2023-03-20 19:29:49 +01:00 committed by GitHub
parent 19eef2c584
commit 3d965b5b81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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;
}

View File

@ -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"