Fix warning, and better tests for __VA_ARGS__

This commit is contained in:
Dale Weiler 2013-01-27 13:03:02 +00:00
parent 001d853f38
commit 6fc5b32123
3 changed files with 20 additions and 10 deletions

View file

@ -720,7 +720,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param
break;
case TOKEN_VA_ARGS_ARRAY:
if (out->constval.i >= varargs) {
if ((size_t)out->constval.i >= varargs) {
ftepp_error(ftepp, "subscript of `[%u]` is out of bounds for `__VA_ARGS__`", out->constval.i);
vec_free(old_string);
return false;

View file

@ -1,12 +1,21 @@
void print(...) = #1;
#define NOPARENS(...) __VA_ARGS__
#define callem(func, args) func NOPARENS(args)
// method 0
#define METHOD__(...) __VA_ARGS__
#define METHOD_0(F,A) F METHOD__(A)
#define callen(func, ...) func __VA_ARGS__##[0]
// method 1
#define METHOD_1(F,A) F(METHOD__ A)
// method 2
#define METHOD_2(F,...) F __VA_ARGS__##[0]
// method 3
#define METHOD_3(F,...) F __VA_ARGS__
void main() {
print(NOPARENS("hello ", "world\n"));
callem(print, ("Yay", ", there\n"));
callen(print, ("Woah",", there\n"));
METHOD_0(print, ("Method", " <zero>\n"));
METHOD_1(print, ("Method", " <one>\n"));
METHOD_2(print, ("Method", " <two>\n"));
METHOD_3(print, ("Method", " <three>\n"));
}

View file

@ -2,6 +2,7 @@ I: pp_va_args.qc
D: __VA_ARGS__
T: -execute
C: -std=fteqcc
M: hello world
M: Yay, there
M: Woah, there
M: Method <zero>
M: Method <one>
M: Method <two>
M: Method <three>