From 447af36d43000bd7ec2ba98ae8112841996de399 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 11 Feb 2025 19:52:25 +0900 Subject: [PATCH] [qfcc] Make __VA_ARGS__ an actual macro parameter It seems I hadn't understood the C spec very well when I implemented __VA_ARGS__ as reading it again now was (after a bit of extra thought) helpful in realizing that __VA_ARGS__ is simply a proper name for the ... "parameter". Fixes __VA_ARGS__ not expanding in the arguments to another macro. I think the __VA_ARGS__ magic macro is no longer needed, but I need to test it properly before deleting it outright. --- tools/qfcc/source/cpp.c | 2 +- tools/qfcc/source/qc-lex.l | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/qfcc/source/cpp.c b/tools/qfcc/source/cpp.c index 2de7aff2f..c055aa81e 100644 --- a/tools/qfcc/source/cpp.c +++ b/tools/qfcc/source/cpp.c @@ -427,7 +427,7 @@ void cpp_define (const char *arg) cpp_macros = new_symtab (0, stab_global); make_magic_macro (cpp_macros, "__FILE__", rua_macro_file); make_magic_macro (cpp_macros, "__LINE__", rua_macro_line); - make_magic_macro (cpp_macros, "__VA_ARGS__", rua_macro_va_args); + //make_magic_macro (cpp_macros, "__VA_ARGS__", rua_macro_va_args); } size_t len = strlen (arg); if (len > 0x10000) { diff --git a/tools/qfcc/source/qc-lex.l b/tools/qfcc/source/qc-lex.l index 16193972d..375bde818 100644 --- a/tools/qfcc/source/qc-lex.l +++ b/tools/qfcc/source/qc-lex.l @@ -1756,7 +1756,11 @@ rua_macro_param (rua_macro_t *macro, const rua_tok_t *token, rua_ctx_t *ctx) error (0, "duplicate macro parameter \"%s\"", token->text); return macro; } - auto sym = new_symbol (token->text); + auto name = token->text; + if (token->token == -rua_ellipsis) { + name = "__VA_ARGS__"; + } + auto sym = new_symbol (name); sym->sy_type = sy_offset; sym->offset = macro->num_params++; symtab_addsymbol (macro->params, sym);