feat: treat unknown macros with arguments as undefined
This commit is contained in:
parent
08a4c52de3
commit
c85eface68
2 changed files with 27 additions and 0 deletions
14
tccpp.c
14
tccpp.c
|
@ -1506,6 +1506,20 @@ static int expr_preprocess(TCCState *s1)
|
||||||
tokc.i = c;
|
tokc.i = c;
|
||||||
} else {
|
} else {
|
||||||
/* if undefined macro, replace with zero */
|
/* if undefined macro, replace with zero */
|
||||||
|
next_nomacro();
|
||||||
|
// If the undefined macro is followed by parens, just skip them.
|
||||||
|
if (tok == '(') {
|
||||||
|
int bracket_depth = 1;
|
||||||
|
while (bracket_depth > 0) {
|
||||||
|
next();
|
||||||
|
if (tok == '(')
|
||||||
|
bracket_depth++;
|
||||||
|
else if (tok == ')')
|
||||||
|
bracket_depth--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unget_tok(tok); // Is this actually the function I want?
|
||||||
|
}
|
||||||
tok = TOK_CINT;
|
tok = TOK_CINT;
|
||||||
tokc.i = 0;
|
tokc.i = 0;
|
||||||
}
|
}
|
||||||
|
|
13
tests/undef_func_macro.c
Normal file
13
tests/undef_func_macro.c
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
int main () {
|
||||||
|
// This used to evaluate to 0 (0), which is invalid.
|
||||||
|
// Now it should evaluate to 0.
|
||||||
|
#if WUMBOED(WUMBO)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Just trying a more complicated test case.
|
||||||
|
#if WUMBO && defined(WUMBOLOGY) || WUMBOED(WUMBO) && !WUMBOLOGY
|
||||||
|
return 0;
|
||||||
|
#elif WUMBO && defined(WUMBOLOGY) || WUMBOED(WUMBO) && !WUMBOLOGY
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
Reference in a new issue