Fixed #5081 (False positive: (error) Uninitialized variable: f (handling of C-cast not correct))

This commit is contained in:
Daniel Marjamäki 2013-11-28 16:04:47 +01:00
parent 6b4016be42
commit 0c5282b1af
2 changed files with 8 additions and 2 deletions

View File

@ -4838,9 +4838,9 @@ void Tokenizer::simplifyCasts()
}
while ((Token::Match(tok->next(), "( %type% *| *| *| ) *|&| %var%") && (tok->str() != ")" || tok->tokAt(2)->isStandardType())) ||
Token::Match(tok->next(), "( %type% %type% *| *| *| ) *|&| %var%") ||
Token::Match(tok->next(), "( const| %type% %type% *| *| *| ) *|&| %var%") ||
(!tok->isName() && (Token::Match(tok->next(), "( %type% * *| *| ) (") ||
Token::Match(tok->next(), "( %type% %type% * *| *| ) (")))) {
Token::Match(tok->next(), "( const| %type% %type% * *| *| ) (")))) {
if (tok->isName() && tok->str() != "return")
break;

View File

@ -97,6 +97,7 @@ private:
TEST_CASE(removeCast11);
TEST_CASE(removeCast12);
TEST_CASE(removeCast13);
TEST_CASE(removeCast14);
TEST_CASE(simplifyFloatCasts); // float casting a integer
@ -1130,6 +1131,11 @@ private:
tokenizeAndStringify("; float angle = (float) +tilt;", true));
}
void removeCast14() { // const
// #5081
ASSERT_EQUALS("( ! ( & s ) . a )", tokenizeAndStringify("(! ( (struct S const *) &s)->a)", true));
}
void simplifyFloatCasts() { // float casting integers
// C-style casts
ASSERT_EQUALS("a = 1.0f ;", tokenizeAndStringify("a = (float)1;"));