Visitar URL original
Fixed MACRO() expansion in #if condition · versat/simplecpp@229d41f · GitHub
Skip to content

Commit 229d41f

Browse files
committed
Fixed MACRO() expansion in #if condition
1 parent 44434ee commit 229d41f

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎simplecpp.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,6 +2750,9 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
27502750
output.clear();
27512751
return;
27522752
}
2753+
if (!tmp)
2754+
break;
2755+
tok = tmp->previous;
27532756
}
27542757
try {
27552758
conditionIsTrue = (evaluate(expr, sizeOfType) != 0);

‎test.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,15 @@ static void ifalt() // using "and", "or", etc
10011001
ASSERT_EQUALS("\n1", preprocess(code));
10021002
}
10031003

1004+
static void ifexpr()
1005+
{
1006+
const char *code = "#define MACRO() (1)\n"
1007+
"#if ~MACRO() & 8\n"
1008+
"1\n"
1009+
"#endif";
1010+
ASSERT_EQUALS("\n\n1", preprocess(code));
1011+
}
1012+
10041013
static void location1()
10051014
{
10061015
const char *code;
@@ -1903,6 +1912,7 @@ int main(int argc, char **argv)
19031912
TEST_CASE(ifoverflow);
19041913
TEST_CASE(ifdiv0);
19051914
TEST_CASE(ifalt); // using "and", "or", etc
1915+
TEST_CASE(ifexpr);
19061916

19071917
TEST_CASE(location1);
19081918
TEST_CASE(location2);

0 commit comments

Comments
 (0)