From e8cd9411b0b03659a14f64225915ec23b696a81d Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Sat, 22 Dec 2012 18:16:41 +0100 Subject: [PATCH] -Wunknown-attribute; and don't error on unknown attributes --- opts.c | 1 + opts.def | 1 + parser.c | 11 +++++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/opts.c b/opts.c index 6008fb1..43c4563 100644 --- a/opts.c +++ b/opts.c @@ -53,6 +53,7 @@ static void opts_setdefault() { opts_set(opts.warn, WARN_UNKNOWN_PRAGMAS, true); opts_set(opts.warn, WARN_UNREACHABLE_CODE, true); opts_set(opts.warn, WARN_CPP, true); + opts_set(opts.warn, WARN_UNKNOWN_ATTRIBUTE, 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 9e53ff5..697afdc 100644 --- a/opts.def +++ b/opts.def @@ -73,6 +73,7 @@ GMQCC_DEFINE_FLAG(UNKNOWN_PRAGMAS) GMQCC_DEFINE_FLAG(UNREACHABLE_CODE) GMQCC_DEFINE_FLAG(CPP) + GMQCC_DEFINE_FLAG(UNKNOWN_ATTRIBUTE) #endif #ifdef GMQCC_TYPE_OPTIMIZATIONS diff --git a/parser.c b/parser.c index a941f03..16d783a 100644 --- a/parser.c +++ b/parser.c @@ -2349,19 +2349,23 @@ static bool parse_var_qualifiers(parser_t *parser, bool with_local, int *cvq, bo bool had_var = false; bool had_noref = false; bool had_noreturn = false; + bool had_attrib = false; - *cvq = CV_WRONG; + *cvq = CV_NONE; for (;;) { if (parser->tok == TOKEN_ATTRIBUTE_OPEN) { + had_attrib = true; /* parse an attribute */ if (!parser_next(parser)) { parseerror(parser, "expected attribute after `[[`"); + *cvq = CV_WRONG; return false; } if (!strcmp(parser_tokval(parser), "noreturn")) { had_noreturn = true; if (!parser_next(parser) || parser->tok != TOKEN_ATTRIBUTE_CLOSE) { parseerror(parser, "`noreturn` attribute has no parameters, expected `]]`"); + *cvq = CV_WRONG; return false; } } @@ -2369,15 +2373,18 @@ static bool parse_var_qualifiers(parser_t *parser, bool with_local, int *cvq, bo had_noref = true; if (!parser_next(parser) || parser->tok != TOKEN_ATTRIBUTE_CLOSE) { parseerror(parser, "`noref` attribute has no parameters, expected `]]`"); + *cvq = CV_WRONG; return false; } } else { /* Skip tokens until we hit a ]] */ + (void)!parsewarning(parser, WARN_UNKNOWN_ATTRIBUTE, "unknown attribute starting with `%s`", parser_tokval(parser)); while (parser->tok != TOKEN_ATTRIBUTE_CLOSE) { if (!parser_next(parser)) { parseerror(parser, "error inside attribute"); + *cvq = CV_WRONG; return false; } } @@ -2391,7 +2398,7 @@ static bool parse_var_qualifiers(parser_t *parser, bool with_local, int *cvq, bo had_var = true; else if (!strcmp(parser_tokval(parser), "noref")) had_noref = true; - else if (!had_const && !had_var && !had_noref && !had_noreturn) { + else if (!had_const && !had_var && !had_noref && !had_noreturn && !had_attrib) { return false; } else -- 2.39.2