Skip to content

Commit b5cb0f8

Browse files
Fix #12730 FP initializerList - name clash? (#6402)
1 parent 994c015 commit b5cb0f8

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/checkclass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,6 +2682,8 @@ void CheckClass::initializerListOrder()
26822682
tok = end;
26832683

26842684
for (; tok != end; tok = tok->next()) {
2685+
if (Token::Match(tok->astParent(), ".|::"))
2686+
continue;
26852687
if (const Variable* argVar = scope->getVariable(tok->str())) {
26862688
if (scope != argVar->scope())
26872689
continue;

test/testclass.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7645,6 +7645,22 @@ class TestClass : public TestFixture {
76457645
"};\n");
76467646
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",
76477647
errout_str());
7648+
7649+
checkInitializerListOrder("struct S { double d = 0; };\n" // #12730
7650+
"struct T {\n"
7651+
" T() : s(), a(s.d), d(0) {}\n"
7652+
" S s;\n"
7653+
" double a, d;\n"
7654+
"};\n");
7655+
ASSERT_EQUALS("", errout_str());
7656+
7657+
checkInitializerListOrder("struct S { static const int d = 1; };\n"
7658+
"struct T {\n"
7659+
" T() : s(), a(S::d), d(0) {}\n"
7660+
" S s;\n"
7661+
" int a, d;\n"
7662+
"};\n");
7663+
ASSERT_EQUALS("", errout_str());
76487664
}
76497665

76507666
#define checkInitializationListUsage(code) checkInitializationListUsage_(code, __FILE__, __LINE__)

0 commit comments

Comments
 (0)