diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index f1a87685b..2b80383d5 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2677,6 +2677,10 @@ void CheckClass::initializerListOrder() if (const Variable* argVar = scope->getVariable(tok->str())) { if (scope != argVar->scope()) continue; + if (argVar->isStatic()) + continue; + if (tok->variable() && tok->variable()->isArgument()) + 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 abb77819b..785b6fcf0 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -7632,6 +7632,20 @@ private: " int j;\n" "};"); ASSERT_EQUALS("", errout.str()); + + checkInitializerListOrder("struct S {\n" + " S() : a(i) {}\n" + " int a;\n" + " static int i;\n" + "};\n" + "int S::i = 0;"); + ASSERT_EQUALS("", errout.str()); + + checkInitializerListOrder("struct S {\n" + " S(int b) : a(b) {}\n" + " int a, b{};\n" + "};"); + ASSERT_EQUALS("", errout.str()); } #define checkInitializationListUsage(code) checkInitializationListUsage_(code, __FILE__, __LINE__)