From b5cb0f871338e95f1ce8751bd18a7ceb8a9af467 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 15 May 2024 14:52:33 +0200 Subject: [PATCH] Fix #12730 FP initializerList - name clash? (#6402) --- lib/checkclass.cpp | 2 ++ test/testclass.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 19dade8114e..84ff52c589b 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::Match(tok->astParent(), ".|::")) + continue; if (const Variable* argVar = scope->getVariable(tok->str())) { if (scope != argVar->scope()) continue; diff --git a/test/testclass.cpp b/test/testclass.cpp index b51435580e2..accc15af5b5 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -7645,6 +7645,22 @@ 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()); + + 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__)