Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FP initializerList for constructor args #5865

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2666,13 +2666,13 @@ void CheckClass::initializerListOrder()
// find all variable initializations in list
for (; tok && tok != func->functionScope->bodyStart; tok = tok->next()) {
if (Token::Match(tok, "%name% (|{")) {
const Token* const end = tok->linkAt(1);
const Variable *var = scope->getVariable(tok->str());
if (var)
vars.emplace_back(var, tok);
else
continue;
tok = end;

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())
Expand Down
23 changes: 23 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7578,6 +7578,29 @@ class TestClass : public TestFixture {
" int a, b;\n"
"};");
ASSERT_EQUALS("", errout.str());

checkInitializerListOrder("struct S {\n"
" int nCols() const;\n"
" int nRows() const;\n"
"};\n"
"struct B {\n"
" const char* m_name;\n"
" int nCols;\n"
" int nRows;\n"
" B(const char* p_name, int nR, int nC)\n"
" : m_name(p_name)\n"
" , nCols(nC)\n"
" , nRows(nR)\n"
" {}\n"
"};\n"
"struct D : public B {\n"
" const int m_i;\n"
" D(const S& s, int _i)\n"
" : B(\"abc\", s.nRows(), s.nCols())\n"
" , m_i(_i)\n"
" {}\n"
"};");
ASSERT_EQUALS("", errout.str());
}

void initializerListArgument() {
Expand Down
Loading