Fix #10744 FP constVariable with static pointer (#3957)

This commit is contained in:
chrchr-github 2022-03-30 19:21:09 +02:00 committed by GitHub
parent 948bb8df94
commit 47ba053054
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -1593,7 +1593,7 @@ void CheckOther::checkConstPointer()
if (nonConstPointers.find(p) == nonConstPointers.end()) {
const Token *start = (p->isArgument()) ? p->scope()->bodyStart : p->nameToken()->next();
const int indirect = p->isArray() ? p->dimensions().size() : 1;
if (isVariableChanged(start, p->scope()->bodyEnd, indirect, p->declarationId(), false, mSettings, mTokenizer->isCPP()))
if (p->isStatic() || isVariableChanged(start, p->scope()->bodyEnd, indirect, p->declarationId(), false, mSettings, mTokenizer->isCPP()))
continue;
constVariableError(p, nullptr);
}

View File

@ -2971,6 +2971,13 @@ private:
" istr >> x[0];\n"
"}");
ASSERT_EQUALS("", errout.str());
// #10744
check("S& f() {\n"
" static S * p = new S();\n"
" return *p;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void switchRedundantAssignmentTest() {

View File

@ -2206,6 +2206,19 @@ private:
"} ;",
tokenizeAndStringify(code));
}
{
// Ticket #9515
const char code[] = "void(a)(void) {\n"
" static int b;\n"
" if (b) {}\n"
"}\n";
ASSERT_EQUALS("void ( a ) ( void ) {\n"
"static int b ;\n"
"if ( b ) { }\n"
"}",
tokenizeAndStringify(code));
}
}
void vardecl6() {