diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 5934dcd85..f1a87685b 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2675,6 +2675,8 @@ void CheckClass::initializerListOrder() 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()) + continue; if (var->isPointer() && (argVar->isArray() || Token::simpleMatch(tok->astParent(), "&"))) continue; if (var->isReference()) diff --git a/test/testclass.cpp b/test/testclass.cpp index f6dddcdce..abb77819b 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -7623,6 +7623,15 @@ private: " int i{};\n" "};"); ASSERT_EQUALS("", errout.str()); + + checkInitializerListOrder("struct B {\n" + " int a{}, b{};\n" + "};\n" + "struct D : B {\n" + " D() : B(), j(b) {}\n" + " int j;\n" + "};"); + ASSERT_EQUALS("", errout.str()); } #define checkInitializationListUsage(code) checkInitializationListUsage_(code, __FILE__, __LINE__)