Fixed #2917 (Problem with || in #if)

This commit is contained in:
Daniel Marjamäki 2011-07-18 21:44:23 +02:00
parent ed30edf9d3
commit b66e6e73db
2 changed files with 15 additions and 3 deletions

View File

@ -1551,7 +1551,8 @@ void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &c
while (modified)
{
modified = false;
tokenizer.simplifyCalculations();
modified |= tokenizer.simplifyCalculations();
modified |= tokenizer.simplifyRedundantParenthesis();
for (Token *tok = const_cast<Token *>(tokenizer.tokens()); tok; tok = tok->next())
{
if (Token::Match(tok, "! %num%"))

View File

@ -204,7 +204,8 @@ private:
TEST_CASE(ifdef_ifdefined);
// define and then ifdef
TEST_CASE(define_if);
TEST_CASE(define_if1);
TEST_CASE(define_if2);
TEST_CASE(define_ifdef);
TEST_CASE(define_ifndef1);
TEST_CASE(define_ifndef2);
@ -2528,7 +2529,7 @@ private:
ASSERT_EQUALS(2, static_cast<unsigned int>(actual.size()));
}
void define_if()
void define_if1()
{
{
const char filedata[] = "#define A 0\n"
@ -2546,6 +2547,16 @@ private:
}
}
void define_if2()
{
const char filedata[] = "#define A 22\n"
"#define B A\n"
"#if (B==A) || (B==C)\n"
"FOO\n"
"#endif";
ASSERT_EQUALS("\n\n\nFOO\n\n", Preprocessor::getcode(filedata,"","",NULL,NULL));
}
void define_ifdef()
{
{