From 77d454725a41686b5ebc80dc0e2708ff909ab113 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 28 Dec 2012 18:22:09 +0100 Subject: [PATCH] -Wreserved-names, -fpermissive allows local variables named 'nil' to be created even with -funtyped-nil, they supersede the global untyped 'nil' --- opts.c | 1 + opts.def | 2 ++ parser.c | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/opts.c b/opts.c index 334186b..0594b37 100644 --- a/opts.c +++ b/opts.c @@ -54,6 +54,7 @@ static void opts_setdefault() { opts_set(opts.warn, WARN_UNREACHABLE_CODE, true); opts_set(opts.warn, WARN_CPP, true); opts_set(opts.warn, WARN_UNKNOWN_ATTRIBUTE, true); + opts_set(opts.warn, WARN_RESERVED_NAMES, true); /* flags */ opts_set(opts.flags, ADJUST_VECTOR_FIELDS, true); opts_set(opts.flags, FTEPP, false); diff --git a/opts.def b/opts.def index a77ebe5..1dc3d5c 100644 --- a/opts.def +++ b/opts.def @@ -47,6 +47,7 @@ GMQCC_DEFINE_FLAG(BAIL_ON_WERROR) GMQCC_DEFINE_FLAG(LOOP_LABELS) GMQCC_DEFINE_FLAG(UNTYPED_NIL) + GMQCC_DEFINE_FLAG(PERMISSIVE) #endif /* warning flags */ @@ -78,6 +79,7 @@ GMQCC_DEFINE_FLAG(UNREACHABLE_CODE) GMQCC_DEFINE_FLAG(CPP) GMQCC_DEFINE_FLAG(UNKNOWN_ATTRIBUTE) + GMQCC_DEFINE_FLAG(RESERVED_NAMES) #endif #ifdef GMQCC_TYPE_OPTIMIZATIONS diff --git a/parser.c b/parser.c index 78dd48d..a47c6ad 100644 --- a/parser.c +++ b/parser.c @@ -4283,6 +4283,13 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield * Also: if there was a prototype, `var` will be deleted and set to `proto` which * is then filled with the previous definition and the parameter-names replaced. */ + if (!strcmp(var->name, "nil")) { + if (OPTS_FLAG(UNTYPED_NIL)) { + if (!localblock || !OPTS_FLAG(PERMISSIVE)) + parseerror(parser, "name `nil` not allowed (try -fpermissive)"); + } else + (void)!parsewarning(parser, WARN_RESERVED_NAMES, "variable name `nil` is reserved"); + } if (!localblock) { /* Deal with end_sys_ vars */ was_end = false; -- 2.39.2