Fixed #7267 (Tokenizer::setVarId: wrongly sets varId in cast with unknown type)

This commit is contained in:
Daniel Marjamäki 2016-01-06 17:47:59 +01:00
parent b2386fa011
commit 88a525aca7
2 changed files with 11 additions and 2 deletions

View File

@ -2700,7 +2700,9 @@ void Tokenizer::setVarId()
}
if (tok == list.front() || Token::Match(tok, "[;{}]") ||
(Token::Match(tok, "[(,]") && (!scopeStack.top().isExecutable || Token::simpleMatch(tok->link(), ") {"))) ||
(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

View File

@ -89,6 +89,7 @@ private:
TEST_CASE(varid57); // #6636: new scope by {}
TEST_CASE(varid58); // #6638: for loop in for condition
TEST_CASE(varid59); // #6696
TEST_CASE(varid60); // #7267 cast '(unsigned x)10'
TEST_CASE(varid_cpp_keywords_in_c_code);
TEST_CASE(varid_cpp_keywords_in_c_code2); // #5373: varid=0 for argument called "delete"
TEST_CASE(varidFunctionCall1);
@ -923,7 +924,7 @@ private:
const char code[] ="int X::f(int b) const { return(a*b); }";
ASSERT_EQUALS("\n\n##file 0\n"
"1: int X :: f ( int b@1 ) const { return ( a * b@1 ) ; }\n",
tokenize(code, false, "test.c"));
tokenize(code, false));
}
void varid49() { // #3799 - void f(std::vector<int>)
@ -1092,6 +1093,12 @@ private:
TODO_ASSERT_EQUALS(wanted, expected, tokenize(code, false, "test.cpp"));
}
void varid60() { // #7267 - cast
ASSERT_EQUALS("\n\n##file 0\n"
"1: a = ( x y ) 10 ;\n",
tokenize("a=(x y)10;", false));
}
void varid_cpp_keywords_in_c_code() {
const char code[] = "void f() {\n"
" delete d;\n"