diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 1ad6cfb4aed..7f5e7e289d5 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2674,7 +2674,7 @@ void CheckClass::initializerListOrder() const Token* const end = tok->next()->link(); for (const Token* tok2 = tok->next(); tok2 != end; tok2 = tok2->next()) { - if (const Variable* var2 = tok2->variable()) + if (const Variable* var2 = scope->getVariable(tok2->str())) vars.back().initArgs.emplace_back(var2); } tok = end; diff --git a/test/testclass.cpp b/test/testclass.cpp index efe3b206689..e13e7c40aeb 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -7590,6 +7590,12 @@ class TestClass : public TestFixture { "};"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument due to the order of declarations.\n", errout.str()); + + checkInitializerListOrder("struct S {\n" + " S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\n" + " int a, b, c;\n" + "};"); + ASSERT_EQUALS("", errout.str()); } #define checkInitializationListUsage(code) checkInitializationListUsage_(code, __FILE__, __LINE__)