Partial fix for #4931 (Wrong calculation of constants (simplifying: +,<<,% operations))

This commit is contained in:
Daniel Marjamäki 2015-11-20 16:09:47 +01:00
parent c0e33e20b4
commit 4abc0b7c1f
2 changed files with 21 additions and 6 deletions

View File

@ -4738,16 +4738,22 @@ bool Tokenizer::simplifyConditions()
ret = true;
}
if (Token::simpleMatch(tok, "( true &&") ||
Token::simpleMatch(tok, "&& true &&") ||
Token::simpleMatch(tok->next(), "&& true )")) {
if (Token::simpleMatch(tok, "&& true &&")) {
tok->deleteNext(2);
ret = true;
}
else if (Token::simpleMatch(tok, "( false ||") ||
Token::simpleMatch(tok, "|| false ||") ||
Token::simpleMatch(tok->next(), "|| false )")) {
else if (Token::simpleMatch(tok, "|| false ||")) {
tok->deleteNext(2);
ret = true;
}
else if (Token::Match(tok, "(|&& true && true &&|)")) {
tok->deleteNext(2);
ret = true;
}
else if (Token::Match(tok, "%oror%|( false %oror% false %oror%|)")) {
tok->deleteNext(2);
ret = true;
}

View File

@ -2653,6 +2653,15 @@ private:
"}";
ASSERT_EQUALS("void f ( int a ) { g ( ) ; }", tok(code));
}
{
// #4931
const char code[] =
"void f() {\n"
"if (12 && 7) g();\n"
"}";
ASSERT_EQUALS("void f ( ) { g ( ) ; }", tok(code));
}
}