Skip to content

Commit

Permalink
Fix FP initializerList for constructor args
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jan 10, 2024
1 parent 5ef846a commit 88a76af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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

0 comments on commit 88a76af

Please sign in to comment.