Fix FP initializerList with static member (#5864)

This commit is contained in:
chrchr-github 2024-01-09 19:42:23 +01:00 committed by GitHub
parent 9fceba4fbc
commit 30397f0d53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -2677,6 +2677,10 @@ void CheckClass::initializerListOrder()
if (const Variable* argVar = scope->getVariable(tok->str())) { if (const Variable* argVar = scope->getVariable(tok->str())) {
if (scope != argVar->scope()) if (scope != argVar->scope())
continue; continue;
if (argVar->isStatic())
continue;
if (tok->variable() && tok->variable()->isArgument())
continue;
if (var->isPointer() && (argVar->isArray() || Token::simpleMatch(tok->astParent(), "&"))) if (var->isPointer() && (argVar->isArray() || Token::simpleMatch(tok->astParent(), "&")))
continue; continue;
if (var->isReference()) if (var->isReference())

View File

@ -7632,6 +7632,20 @@ private:
" int j;\n" " int j;\n"
"};"); "};");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkInitializerListOrder("struct S {\n"
" S() : a(i) {}\n"
" int a;\n"
" static int i;\n"
"};\n"
"int S::i = 0;");
ASSERT_EQUALS("", errout.str());
checkInitializerListOrder("struct S {\n"
" S(int b) : a(b) {}\n"
" int a, b{};\n"
"};");
ASSERT_EQUALS("", errout.str());
} }
#define checkInitializationListUsage(code) checkInitializationListUsage_(code, __FILE__, __LINE__) #define checkInitializationListUsage(code) checkInitializationListUsage_(code, __FILE__, __LINE__)