Skip to content

Commit

Permalink
Fixed MACRO() expansion in #if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ew-dm committed Jul 3, 2019
1 parent 44434ee commit 229d41f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,9 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
output.clear();
return;
}
if (!tmp)
break;
tok = tmp->previous;
}
try {
conditionIsTrue = (evaluate(expr, sizeOfType) != 0);
Expand Down
10 changes: 10 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,15 @@ static void ifalt() // using "and", "or", etc
ASSERT_EQUALS("\n1", preprocess(code));
}

static void ifexpr()
{
const char *code = "#define MACRO() (1)\n"
"#if ~MACRO() & 8\n"
"1\n"
"#endif";
ASSERT_EQUALS("\n\n1", preprocess(code));
}

static void location1()
{
const char *code;
Expand Down Expand Up @@ -1903,6 +1912,7 @@ int main(int argc, char **argv)
TEST_CASE(ifoverflow);
TEST_CASE(ifdiv0);
TEST_CASE(ifalt); // using "and", "or", etc
TEST_CASE(ifexpr);

TEST_CASE(location1);
TEST_CASE(location2);
Expand Down

0 comments on commit 229d41f

Please sign in to comment.