diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 19dade8114e..84ff52c589b 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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; diff --git a/test/testclass.cpp b/test/testclass.cpp index b51435580e2..accc15af5b5 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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__)