diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6bdee6618dc..9002f514813 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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 (")) { 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() {