Skip to content

Commit

Permalink
Fix FP initializerList with static member (#5864)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jan 9, 2024
1 parent 9fceba4 commit 30397f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2677,6 +2677,10 @@ void CheckClass::initializerListOrder()
if (const Variable* argVar = scope->getVariable(tok->str())) {
if (scope != argVar->scope())
continue;
if (argVar->isStatic())
continue;
if (tok->variable() && tok->variable()->isArgument())
continue;
if (var->isPointer() && (argVar->isArray() || Token::simpleMatch(tok->astParent(), "&")))
continue;
if (var->isReference())
Expand Down
14 changes: 14 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7632,6 +7632,20 @@ class TestClass : public TestFixture {
" int j;\n"
"};");
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__)
Expand Down

0 comments on commit 30397f0

Please sign in to comment.