Skip to content

Commit

Permalink
Fix #12733 FP constParameterReference with nested init list (danmar#6406
Browse files Browse the repository at this point in the history
)
  • Loading branch information
chrchr-github authored May 21, 2024
1 parent 374e85d commit 97115c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4611,8 +4611,9 @@ void Tokenizer::setVarIdPass1()
if (!(scopeStack.top().isStructInit || tok->strAt(-1) == "="))
variableMap.enterScope();
}
const bool isStructInit = scopeStack.top().isStructInit || tok->strAt(-1) == "=" || (initlist && !Token::Match(tok->tokAt(-1), "[)}]"));
scopeStack.emplace(isExecutable, isStructInit, isEnumStart(tok), variableMap.getVarId());
initlist = false;
scopeStack.emplace(isExecutable, scopeStack.top().isStructInit || tok->strAt(-1) == "=", isEnumStart(tok), variableMap.getVarId());
} else { /* if (tok->str() == "}") */
bool isNamespace = false;
for (const Token *tok1 = tok->link()->previous(); tok1 && tok1->isName(); tok1 = tok1->previous()) {
Expand Down
10 changes: 10 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2520,6 +2520,16 @@ class TestVarID : public TestFixture {
"5: A :: A ( const Matrix & m@3 ) throw ( e ) : work@1 ( 0 )\n"
"6: { }\n",
tokenize(code10));

const char code11[] = "struct S {\n" // #12733
" explicit S(int& r) : a{ int{ 1 } }, b{ r } {}\n"
" int a, &b;\n"
"};";
ASSERT_EQUALS("1: struct S {\n"
"2: explicit S ( int & r@1 ) : a@2 { int { 1 } } , b@3 { r@1 } { }\n"
"3: int a@2 ; int & b@3 ;\n"
"4: } ;\n",
tokenize(code11));
}

void varid_initListWithBaseTemplate() {
Expand Down

0 comments on commit 97115c4

Please sign in to comment.