From 30397f0d539c3192e1ad6fc5593f2d2fbdf38879 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 9 Jan 2024 19:42:23 +0100 Subject: [PATCH] Fix FP initializerList with static member (#5864) --- lib/checkclass.cpp | 4 ++++ test/testclass.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index f1a87685b4c..2b80383d54a 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 abb77819b5b..785b6fcf005 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -7632,6 +7632,20 @@ class TestClass : public TestFixture { " 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__)