diff options
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/c/c-errors.c | 39 | ||||
-rw-r--r-- | gcc/c/c-parser.c | 60 | ||||
-rw-r--r-- | gcc/c/c-tree.h | 2 |
4 files changed, 91 insertions, 20 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 4807a32..2c07f2f 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,13 @@ +2018-10-17 Joseph Myers <joseph@codesourcery.com> + + * c-errors.c (pedwarn_c11): New function. + * c-parser.c (disable_extension_diagnostics): Save + warn_c11_c2x_compat and set it to 0. + (restore_extension_diagnostics): Restore warn_c11_c2x_compat. + (c_parser_static_assert_declaration_no_semi): Handle + _Static_assert without string constant. + * c-tree.h (pedwarn_c11): New prototype. + 2018-10-17 David Malcolm <dmalcolm@redhat.com> * Make-lang.in (selftest-c): New. diff --git a/gcc/c/c-errors.c b/gcc/c/c-errors.c index 2d50710..4ff2080 100644 --- a/gcc/c/c-errors.c +++ b/gcc/c/c-errors.c @@ -25,6 +25,45 @@ along with GCC; see the file COPYING3. If not see #include "c-tree.h" #include "opts.h" +/* Issue an ISO C11 pedantic warning MSGID if -pedantic outside C2X mode, + otherwise issue warning MSGID if -Wc11-c2X-compat is specified. + This function is supposed to be used for matters that are allowed in + ISO C2X but not supported in ISO C11, thus we explicitly don't pedwarn + when C2X is specified. */ + +bool +pedwarn_c11 (location_t location, int opt, const char *gmsgid, ...) +{ + diagnostic_info diagnostic; + va_list ap; + bool warned = false; + rich_location richloc (line_table, location); + + va_start (ap, gmsgid); + /* If desired, issue the C11/C2X compat warning, which is more specific + than -pedantic. */ + if (warn_c11_c2x_compat > 0) + { + diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, + (pedantic && !flag_isoc2x) + ? DK_PEDWARN : DK_WARNING); + diagnostic.option_index = OPT_Wc11_c2x_compat; + warned = diagnostic_report_diagnostic (global_dc, &diagnostic); + } + /* -Wno-c11-c2x-compat suppresses even the pedwarns. */ + else if (warn_c11_c2x_compat == 0) + ; + /* For -pedantic outside C2X, issue a pedwarn. */ + else if (pedantic && !flag_isoc2x) + { + diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN); + diagnostic.option_index = opt; + warned = diagnostic_report_diagnostic (global_dc, &diagnostic); + } + va_end (ap); + return warned; +} + /* Issue an ISO C99 pedantic warning MSGID if -pedantic outside C11 mode, otherwise issue warning MSGID if -Wc99-c11-compat is specified. This function is supposed to be used for matters that are allowed in diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 1f173fc..ee66ce8 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1327,6 +1327,9 @@ disable_extension_diagnostics (void) /* Similarly for warn_c99_c11_compat. */ | ((warn_c99_c11_compat == 1) << 9) | ((warn_c99_c11_compat == -1) << 10) + /* Similarly for warn_c11_c2x_compat. */ + | ((warn_c11_c2x_compat == 1) << 11) + | ((warn_c11_c2x_compat == -1) << 12) ); cpp_opts->cpp_pedantic = pedantic = 0; warn_pointer_arith = 0; @@ -1337,6 +1340,7 @@ disable_extension_diagnostics (void) warn_overlength_strings = 0; warn_c90_c99_compat = 0; warn_c99_c11_compat = 0; + warn_c11_c2x_compat = 0; return ret; } @@ -1356,6 +1360,7 @@ restore_extension_diagnostics (int flags) /* See above for why is this needed. */ warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0); warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0); + warn_c11_c2x_compat = (flags >> 11) & 1 ? 1 : ((flags >> 12) & 1 ? -1 : 0); } /* Helper data structure for parsing #pragma acc routine. */ @@ -2404,6 +2409,10 @@ c_parser_static_assert_declaration (c_parser *parser) static_assert-declaration-no-semi: _Static_assert ( constant-expression , string-literal ) + + C2X: + static_assert-declaration-no-semi: + _Static_assert ( constant-expression ) */ static void @@ -2411,7 +2420,7 @@ c_parser_static_assert_declaration_no_semi (c_parser *parser) { location_t assert_loc, value_loc; tree value; - tree string; + tree string = NULL_TREE; gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)); assert_loc = c_parser_peek_token (parser)->location; @@ -2429,27 +2438,33 @@ c_parser_static_assert_declaration_no_semi (c_parser *parser) value = c_parser_expr_no_commas (parser, NULL).value; value_loc = EXPR_LOC_OR_LOC (value, value_tok_loc); parser->lex_untranslated_string = true; - if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) - { - parser->lex_untranslated_string = false; - return; - } - switch (c_parser_peek_token (parser)->type) + if (c_parser_next_token_is (parser, CPP_COMMA)) { - case CPP_STRING: - case CPP_STRING16: - case CPP_STRING32: - case CPP_WSTRING: - case CPP_UTF8STRING: - string = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); - parser->lex_untranslated_string = false; - break; - default: - c_parser_error (parser, "expected string literal"); - parser->lex_untranslated_string = false; - return; + switch (c_parser_peek_token (parser)->type) + { + case CPP_STRING: + case CPP_STRING16: + case CPP_STRING32: + case CPP_WSTRING: + case CPP_UTF8STRING: + string = c_parser_peek_token (parser)->value; + c_parser_consume_token (parser); + parser->lex_untranslated_string = false; + break; + default: + c_parser_error (parser, "expected string literal"); + parser->lex_untranslated_string = false; + return; + } } + else if (flag_isoc11) + /* If pedantic for pre-C11, the use of _Static_assert itself will + have been diagnosed, so do not also diagnose the use of this + new C2X feature of _Static_assert. */ + pedwarn_c11 (assert_loc, OPT_Wpedantic, + "ISO C11 does not support omitting the string in " + "%<_Static_assert%>"); parens.require_close (parser); if (!INTEGRAL_TYPE_P (TREE_TYPE (value))) @@ -2473,7 +2488,12 @@ c_parser_static_assert_declaration_no_semi (c_parser *parser) } constant_expression_warning (value); if (integer_zerop (value)) - error_at (assert_loc, "static assertion failed: %E", string); + { + if (string) + error_at (assert_loc, "static assertion failed: %E", string); + else + error_at (assert_loc, "static assertion failed"); + } } /* Parse some declaration specifiers (possibly none) (C90 6.5, C99 diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 017c01c..be63fee 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -762,6 +762,8 @@ extern bool pedwarn_c90 (location_t, int opt, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); extern bool pedwarn_c99 (location_t, int opt, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); +extern bool pedwarn_c11 (location_t, int opt, const char *, ...) + ATTRIBUTE_GCC_DIAG(3,4); extern void set_c_expr_source_range (c_expr *expr, |