Expand macros in the #if and #elif argument context

This commit is contained in:
Rui Ueyama 2020-08-20 19:36:49 +09:00
parent 9ad60e41d5
commit 2651448084
2 changed files with 19 additions and 0 deletions

View File

@ -20,6 +20,8 @@ struct CondIncl {
static Macro *macros;
static CondIncl *cond_incl;
static Token *preprocess2(Token *tok);
static bool is_hash(Token *tok) {
return tok->at_bol && equal(tok, "#");
}
@ -113,6 +115,7 @@ static Token *copy_line(Token **rest, Token *tok) {
static long eval_const_expr(Token **rest, Token *tok) {
Token *start = tok;
Token *expr = copy_line(rest, tok->next);
expr = preprocess2(expr);
if (expr->kind == TK_EOF)
error_tok(start, "no expression");

View File

@ -128,6 +128,22 @@ int main() {
if (0);
#define M 5
#if M
m = 5;
#else
m = 6;
#endif
assert(5, m, "m");
#define M 5
#if M-5
m = 6;
#elif M
m = 5;
#endif
assert(5, m, "m");
printf("OK\n");
return 0;
}