From 9fceba4fbc97c0aaf9da3ca709aca1686b61bb48 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:52:32 +0100 Subject: [PATCH] Fix FP initializerList with base member (#5862) --- lib/checkclass.cpp | 2 ++ test/testclass.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) 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__)