Skip to content

Commit 4bbd1bf

Browse files
authored
Fix #452: Undefined function-style macro does not cause an error (#453)
1 parent c1f3688 commit 4bbd1bf

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

simplecpp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,8 @@ static void simplifyName(simplecpp::TokenList &expr)
28272827
if (alt)
28282828
continue;
28292829
}
2830+
if (tok->next && tok->next->str() == "(")
2831+
throw std::runtime_error("undefined function-like macro invocation: " + tok->str() + "( ... )");
28302832
tok->setstr("0");
28312833
}
28322834
}

test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,6 +1879,15 @@ static void ifexpr()
18791879
ASSERT_EQUALS("\n\n1", preprocess(code));
18801880
}
18811881

1882+
static void ifUndefFuncStyleMacro()
1883+
{
1884+
const char code[] = "#if A(<dir/file.h>)\n"
1885+
"#endif\n";
1886+
simplecpp::OutputList outputList;
1887+
ASSERT_EQUALS("", preprocess(code, &outputList));
1888+
ASSERT_EQUALS("file0,1,syntax_error,failed to evaluate #if condition, undefined function-like macro invocation: A( ... )\n", toString(outputList));
1889+
}
1890+
18821891
static void location1()
18831892
{
18841893
const char *code;
@@ -3202,6 +3211,7 @@ int main(int argc, char **argv)
32023211
TEST_CASE(ifdiv0);
32033212
TEST_CASE(ifalt); // using "and", "or", etc
32043213
TEST_CASE(ifexpr);
3214+
TEST_CASE(ifUndefFuncStyleMacro);
32053215

32063216
TEST_CASE(location1);
32073217
TEST_CASE(location2);

0 commit comments

Comments
 (0)