From d33c622b013767bc48b7e0db686bee90a206f72d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 14 May 2024 14:20:31 +0200 Subject: [PATCH 1/3] Update checkclass.cpp --- lib/checkclass.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 19dade8114e..fa10621d05e 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2682,6 +2682,8 @@ void CheckClass::initializerListOrder() tok = end; for (; tok != end; tok = tok->next()) { + if (Token::simpleMatch(tok->astParent(), ".")) + continue; if (const Variable* argVar = scope->getVariable(tok->str())) { if (scope != argVar->scope()) continue; From 6f220de3af906f318e5f3bbfd36410cacb0d557b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 14 May 2024 14:21:39 +0200 Subject: [PATCH 2/3] Update testclass.cpp --- test/testclass.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/testclass.cpp b/test/testclass.cpp index b51435580e2..6555216b85c 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -7645,6 +7645,14 @@ class TestClass : public TestFixture { "};\n"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations.\n", errout_str()); + + checkInitializerListOrder("struct S { double d = 0; };\n" // #12730 + "struct T {\n" + " T() : s(), a(s.d), d(0) {}\n" + " S s;\n" + " double a, d;\n" + "};\n"); + ASSERT_EQUALS("", errout_str()); } #define checkInitializationListUsage(code) checkInitializationListUsage_(code, __FILE__, __LINE__) From 7f34aae5447babf651cf65eb19479a84761c7e67 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Tue, 14 May 2024 23:40:57 +0200 Subject: [PATCH 3/3] Fix --- lib/checkclass.cpp | 2 +- test/testclass.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index fa10621d05e..84ff52c589b 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2682,7 +2682,7 @@ void CheckClass::initializerListOrder() tok = end; for (; tok != end; tok = tok->next()) { - if (Token::simpleMatch(tok->astParent(), ".")) + if (Token::Match(tok->astParent(), ".|::")) continue; if (const Variable* argVar = scope->getVariable(tok->str())) { if (scope != argVar->scope()) diff --git a/test/testclass.cpp b/test/testclass.cpp index 6555216b85c..accc15af5b5 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -7653,6 +7653,14 @@ class TestClass : public TestFixture { " double a, d;\n" "};\n"); ASSERT_EQUALS("", errout_str()); + + checkInitializerListOrder("struct S { static const int d = 1; };\n" + "struct T {\n" + " T() : s(), a(S::d), d(0) {}\n" + " S s;\n" + " int a, d;\n" + "};\n"); + ASSERT_EQUALS("", errout_str()); } #define checkInitializationListUsage(code) checkInitializationListUsage_(code, __FILE__, __LINE__)