Skip to content

Commit

Permalink
Fix #12730 FP initializerList - name clash? (danmar#6402)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed May 15, 2024
1 parent 994c015 commit b5cb0f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2682,6 +2682,8 @@ void CheckClass::initializerListOrder()
tok = end;

for (; tok != end; tok = tok->next()) {
if (Token::Match(tok->astParent(), ".|::"))
continue;
if (const Variable* argVar = scope->getVariable(tok->str())) {
if (scope != argVar->scope())
continue;
Expand Down
16 changes: 16 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7645,6 +7645,22 @@ class TestClass : public TestFixture {
"};\n");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations.\n",
errout_str());

checkInitializerListOrder("struct S { double d = 0; };\n" // #12730
"struct T {\n"
" T() : s(), a(s.d), d(0) {}\n"
" S s;\n"
" double a, d;\n"
"};\n");
ASSERT_EQUALS("", errout_str());

checkInitializerListOrder("struct S { static const int d = 1; };\n"
"struct T {\n"
" T() : s(), a(S::d), d(0) {}\n"
" S s;\n"
" int a, d;\n"
"};\n");
ASSERT_EQUALS("", errout_str());
}

#define checkInitializationListUsage(code) checkInitializationListUsage_(code, __FILE__, __LINE__)
Expand Down

0 comments on commit b5cb0f8

Please sign in to comment.