Fix FP initializerList with base member (#5862)

This commit is contained in:
chrchr-github 2024-01-09 14:52:32 +01:00 committed by GitHub
parent c21166565f
commit 9fceba4fbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -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())

View File

@ -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__)