diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9a06871ff..216fdd3c8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2732,11 +2732,13 @@ void Tokenizer::setVarIdPass1() } } - if (tok == list.front() || Token::Match(tok, "[;{}]") || - (tok->str() == "(" && isFunctionHead(tok,"{")) || - (tok->str() == "(" && !scopeStack.top().isExecutable && isFunctionHead(tok,";:")) || - (tok->str() == "," && !scopeStack.top().isExecutable) || - (tok->isName() && tok->str().at(tok->str().length()-1U) == ':')) { + 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) || + (tok->isName() && tok->str().at(tok->str().length()-1U) == ':'))) { // No variable declarations in sizeof if (Token::simpleMatch(tok->previous(), "sizeof (")) { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index bd0504c84..5cd7068d7 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -149,6 +149,7 @@ private: TEST_CASE(varid_header); // #6386 TEST_CASE(varid_rangeBasedFor); TEST_CASE(varid_structinit); // #6406 + TEST_CASE(varid_arrayinit); // #7579 TEST_CASE(varidclass1); TEST_CASE(varidclass2); @@ -2301,6 +2302,10 @@ private: "}")); } + 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] }; }")); + } + void varidclass1() { const std::string actual = tokenize( "class Fred\n"