From 3a70012b42123f7a52ef76b0f881cc4eb18ca259 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 12 Feb 2024 11:51:10 +0100 Subject: [PATCH] Fix #12402 debug: Function::addArguments found argument 'i' with varid 0 for lambda parameter --- lib/tokenize.cpp | 6 +++--- test/testvarid.cpp | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6bdee6618dc..8ea5af60d52 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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 (")) { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index d977a8b9536..98780b06653 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -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() {