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
#5975)

…d 0 for lambda parameter
  • Loading branch information
chrchr-github authored Feb 12, 2024
1 parent 6bafd19 commit 4eecf7b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 7 additions & 7 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 &&
(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(), ':')))) {
if ((!scopeStack.top().isStructInit &&
(tok == list.front() ||
Token::Match(tok, "[;{}]") ||
(tok->str() == "(" && !scopeStack.top().isExecutable && isFunctionHead(tok,";:")) ||
(tok->str() == "," && (!scopeStack.top().isExecutable || inlineFunction || !tok->previous()->varId())) ||
(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 4eecf7b

Please sign in to comment.