Skip to content

Commit

Permalink
Fix #12402 debug: Function::addArguments found argument 'i' with vari…
Browse files Browse the repository at this point in the history
…d 0 for lambda parameter
  • Loading branch information
chrchr-github committed Feb 12, 2024
1 parent 503c109 commit 3a70012
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4631,13 +4631,13 @@ void Tokenizer::setVarIdPass1()
}
}

if (!scopeStack.top().isStructInit &&
if ((!scopeStack.top().isStructInit &&
(tok == list.front() ||
Token::Match(tok, "[;{}]") ||
(tok->str() == "(" && isFunctionHead(tok,"{")) ||
(tok->str() == "(" && !scopeStack.top().isExecutable && isFunctionHead(tok,";:")) ||
(tok->str() == "," && (!scopeStack.top().isExecutable || inlineFunction || !tok->previous()->varId())) ||
(tok->isName() && endsWith(tok->str(), ':')))) {
(tok->isName() && endsWith(tok->str(), ':')))) ||
(tok->str() == "(" && isFunctionHead(tok, "{"))) {

// No variable declarations in sizeof
if (Token::simpleMatch(tok->previous(), "sizeof (")) {
Expand Down
6 changes: 5 additions & 1 deletion test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2913,8 +2913,12 @@ class TestVarID : public TestFixture {
"}"));
}

void varid_arrayinit() { // #7579 - no variable declaration in rhs
void varid_arrayinit() {
// #7579 - no variable declaration in rhs
ASSERT_EQUALS("1: void foo ( int * a@1 ) { int b@2 [ 1 ] = { x * a@1 [ 0 ] } ; }\n", tokenize("void foo(int*a) { int b[] = { x*a[0] }; }"));

// #12402
ASSERT_EQUALS("1: void f ( ) { void ( * p@1 [ 1 ] ) ( int ) = { [ ] ( int i@2 ) { } } ; }\n", tokenize("void f() { void (*p[1])(int) = { [](int i) {} }; }"));
}

void varid_lambda_arg() {
Expand Down

0 comments on commit 3a70012

Please sign in to comment.