Fixed #7579 (varid not set properly in 'int b[] = { m * a[0] };')

This commit is contained in:
Daniel Marjamäki 2016-07-18 15:27:08 +02:00
parent f55040a987
commit 83b982064d
2 changed files with 12 additions and 5 deletions

View File

@ -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 (")) {

View File

@ -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"