From: Wolfgang Bumiller Date: Sat, 12 Jan 2013 15:28:04 +0000 (+0100) Subject: guarding vararg code by -fvariadic-args X-Git-Tag: before-library~280 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4df6d1e02822c92ca8203b7c6a3114ebf55726ec;p=xonotic%2Fgmqcc.git guarding vararg code by -fvariadic-args --- diff --git a/opts.def b/opts.def index 4f015b8..65c2d9e 100644 --- a/opts.def +++ b/opts.def @@ -49,6 +49,7 @@ GMQCC_DEFINE_FLAG(UNTYPED_NIL) GMQCC_DEFINE_FLAG(PERMISSIVE) GMQCC_DEFINE_FLAG(ENHANCED_DIAGNOSTICS) + GMQCC_DEFINE_FLAG(VARIADIC_ARGS) #endif /* warning flags */ diff --git a/parser.c b/parser.c index 4459d7b..53c7867 100644 --- a/parser.c +++ b/parser.c @@ -1713,6 +1713,10 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma else if (parser->tok == TOKEN_DOTS) { ast_expression *va; + if (!OPTS_FLAG(VARIADIC_ARGS)) { + parseerror(parser, "cannot access varargs (try -fvariadic-args)"); + goto onerr; + } if (wantop) { parseerror(parser, "expected operator or end of statement"); goto onerr; @@ -3776,7 +3780,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var) return false; } - if (var->expression.flags & AST_FLAG_VARIADIC) { + if (!OPTS_FLAG(VARIADIC_ARGS) && var->expression.flags & AST_FLAG_VARIADIC) { if (parsewarning(parser, WARN_VARIADIC_FUNCTION, "variadic function with implementation will not be able to access additional parameters")) { @@ -4012,7 +4016,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var) func->argc = argc; } - if (var->expression.flags & AST_FLAG_VARIADIC) { + if (OPTS_FLAG(VARIADIC_ARGS) && var->expression.flags & AST_FLAG_VARIADIC) { char name[1024]; ast_value *varargs = ast_value_new(ast_ctx(var), "reserved:va_args", TYPE_ARRAY); varargs->expression.flags |= AST_FLAG_IS_VARARG;