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; break;
case TOKEN_VA_ARGS_ARRAY: 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); ftepp_error(ftepp, "subscript of `[%u]` is out of bounds for `__VA_ARGS__`", out->constval.i);
vec_free(old_string); vec_free(old_string);
return false; return false;

View file

@ -1,12 +1,21 @@
void print(...) = #1; void print(...) = #1;
#define NOPARENS(...) __VA_ARGS__ // method 0
#define callem(func, args) func NOPARENS(args) #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() { void main() {
print(NOPARENS("hello ", "world\n")); METHOD_0(print, ("Method", " <zero>\n"));
callem(print, ("Yay", ", there\n")); METHOD_1(print, ("Method", " <one>\n"));
callen(print, ("Woah",", there\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__ D: __VA_ARGS__
T: -execute T: -execute
C: -std=fteqcc C: -std=fteqcc
M: hello world M: Method <zero>
M: Yay, there M: Method <one>
M: Woah, there M: Method <two>
M: Method <three>