@@ -2818,7 +2818,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
2818
2818
2819
2819
static const char * const altopData[] = {" and" ," or" ," bitand" ," bitor" ," compl" ," not" ," not_eq" ," xor" };
2820
2820
static const std::set<std::string> altop (&altopData[0 ], &altopData[8 ]);
2821
- static void simplifyName (simplecpp::TokenList &expr)
2821
+ static bool simplifyName (simplecpp::TokenList &expr, simplecpp::OutputList *outputList )
2822
2822
{
2823
2823
for (simplecpp::Token *tok = expr.front (); tok; tok = tok->next ) {
2824
2824
if (tok->name ) {
@@ -2832,9 +2832,20 @@ static void simplifyName(simplecpp::TokenList &expr)
2832
2832
if (alt)
2833
2833
continue ;
2834
2834
}
2835
+ if (tok->next && tok->next ->str () == " (" ) {
2836
+ if (outputList) {
2837
+ simplecpp::Output err (tok->location .files );
2838
+ err.type = simplecpp::Output::SYNTAX_ERROR;
2839
+ err.location = tok->location ;
2840
+ err.msg = " Undefined function-like macro in directive" ;
2841
+ outputList->push_back (err);
2842
+ }
2843
+ return false ;
2844
+ }
2835
2845
tok->setstr (" 0" );
2836
2846
}
2837
2847
}
2848
+ return true ;
2838
2849
}
2839
2850
2840
2851
/*
@@ -3106,12 +3117,13 @@ static void simplifyComments(simplecpp::TokenList &expr)
3106
3117
}
3107
3118
}
3108
3119
3109
- static long long evaluate (simplecpp::TokenList &expr, const simplecpp::DUI &dui, const std::map<std::string, std::size_t > &sizeOfType)
3120
+ static long long evaluate (simplecpp::TokenList &expr, const simplecpp::DUI &dui, const std::map<std::string, std::size_t > &sizeOfType, simplecpp::OutputList *outputList )
3110
3121
{
3111
3122
simplifyComments (expr);
3112
3123
simplifySizeof (expr, sizeOfType);
3113
3124
simplifyHasInclude (expr, dui);
3114
- simplifyName (expr);
3125
+ if (!simplifyName (expr, outputList))
3126
+ return 0 ;
3115
3127
simplifyNumbers (expr);
3116
3128
expr.constFold ();
3117
3129
// TODO: handle invalid expressions
@@ -3820,11 +3832,11 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
3820
3832
std::string E;
3821
3833
for (const simplecpp::Token *tok = expr.cfront (); tok; tok = tok->next )
3822
3834
E += (E.empty () ? " " : " " ) + tok->str ();
3823
- const long long result = evaluate (expr, dui, sizeOfType);
3835
+ const long long result = evaluate (expr, dui, sizeOfType, outputList );
3824
3836
conditionIsTrue = (result != 0 );
3825
3837
ifCond->push_back (IfCond (rawtok->location , E, result));
3826
3838
} else {
3827
- const long long result = evaluate (expr, dui, sizeOfType);
3839
+ const long long result = evaluate (expr, dui, sizeOfType, outputList );
3828
3840
conditionIsTrue = (result != 0 );
3829
3841
}
3830
3842
} catch (const std::exception &e) {
0 commit comments