diff --git a/simplecpp.cpp b/simplecpp.cpp index 599ffdf..70364f7 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -2832,6 +2832,8 @@ static void simplifyName(simplecpp::TokenList &expr) if (alt) continue; } + if (tok->next && tok->next->str() == "(") + throw std::runtime_error("undefined function-like macro invocation: " + tok->str() + "( ... )"); tok->setstr("0"); } } diff --git a/test.cpp b/test.cpp index cec253b..18ca8af 100644 --- a/test.cpp +++ b/test.cpp @@ -1825,6 +1825,15 @@ static void ifexpr() ASSERT_EQUALS("\n\n1", preprocess(code)); } +static void ifUndefFuncStyleMacro() +{ + const char code[] = "#if A()\n" + "#endif\n"; + simplecpp::OutputList outputList; + ASSERT_EQUALS("", preprocess(code, &outputList)); + ASSERT_EQUALS("file0,1,syntax_error,failed to evaluate #if condition, undefined function-like macro invocation: A( ... )\n", toString(outputList)); +} + static void location1() { const char *code; @@ -3145,6 +3154,7 @@ int main(int argc, char **argv) TEST_CASE(ifdiv0); TEST_CASE(ifalt); // using "and", "or", etc TEST_CASE(ifexpr); + TEST_CASE(ifUndefFuncStyleMacro); TEST_CASE(location1); TEST_CASE(location2);