Skip to content

Commit 97115c4

Browse files
Fix #12733 FP constParameterReference with nested init list (#6406)
1 parent 374e85d commit 97115c4

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4611,8 +4611,9 @@ void Tokenizer::setVarIdPass1()
46114611
if (!(scopeStack.top().isStructInit || tok->strAt(-1) == "="))
46124612
variableMap.enterScope();
46134613
}
4614+
const bool isStructInit = scopeStack.top().isStructInit || tok->strAt(-1) == "=" || (initlist && !Token::Match(tok->tokAt(-1), "[)}]"));
4615+
scopeStack.emplace(isExecutable, isStructInit, isEnumStart(tok), variableMap.getVarId());
46144616
initlist = false;
4615-
scopeStack.emplace(isExecutable, scopeStack.top().isStructInit || tok->strAt(-1) == "=", isEnumStart(tok), variableMap.getVarId());
46164617
} else { /* if (tok->str() == "}") */
46174618
bool isNamespace = false;
46184619
for (const Token *tok1 = tok->link()->previous(); tok1 && tok1->isName(); tok1 = tok1->previous()) {

test/testvarid.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,16 @@ class TestVarID : public TestFixture {
25202520
"5: A :: A ( const Matrix & m@3 ) throw ( e ) : work@1 ( 0 )\n"
25212521
"6: { }\n",
25222522
tokenize(code10));
2523+
2524+
const char code11[] = "struct S {\n" // #12733
2525+
" explicit S(int& r) : a{ int{ 1 } }, b{ r } {}\n"
2526+
" int a, &b;\n"
2527+
"};";
2528+
ASSERT_EQUALS("1: struct S {\n"
2529+
"2: explicit S ( int & r@1 ) : a@2 { int { 1 } } , b@3 { r@1 } { }\n"
2530+
"3: int a@2 ; int & b@3 ;\n"
2531+
"4: } ;\n",
2532+
tokenize(code11));
25232533
}
25242534

25252535
void varid_initListWithBaseTemplate() {

0 commit comments

Comments
 (0)