diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2b80383d54a..4118d31a896 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2666,13 +2666,13 @@ void CheckClass::initializerListOrder() // find all variable initializations in list for (; tok && tok != func->functionScope->bodyStart; tok = tok->next()) { if (Token::Match(tok, "%name% (|{")) { + const Token* const end = tok->linkAt(1); const Variable *var = scope->getVariable(tok->str()); if (var) vars.emplace_back(var, tok); else - continue; + tok = end; - const Token* const end = tok->next()->link(); for (; tok != end; tok = tok->next()) { if (const Variable* argVar = scope->getVariable(tok->str())) { if (scope != argVar->scope()) diff --git a/test/testclass.cpp b/test/testclass.cpp index 785b6fcf005..317d8956b77 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -7578,6 +7578,29 @@ class TestClass : public TestFixture { " int a, b;\n" "};"); ASSERT_EQUALS("", errout.str()); + + checkInitializerListOrder("struct S {\n" + " int nCols() const;\n" + " int nRows() const;\n" + "};\n" + "struct B {\n" + " const char* m_name;\n" + " int nCols;\n" + " int nRows;\n" + " B(const char* p_name, int nR, int nC)\n" + " : m_name(p_name)\n" + " , nCols(nC)\n" + " , nRows(nR)\n" + " {}\n" + "};\n" + "struct D : public B {\n" + " const int m_i;\n" + " D(const S& s, int _i)\n" + " : B(\"abc\", s.nRows(), s.nCols())\n" + " , m_i(_i)\n" + " {}\n" + "};"); + ASSERT_EQUALS("", errout.str()); } void initializerListArgument() {