diff options
author | Marek Polacek <polacek@redhat.com> | 2014-08-10 06:10:49 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2014-08-10 06:10:49 +0000 |
commit | f3bede718836610fd741175f4a1b74ba5717e283 (patch) | |
tree | ad84805c19739010caa9af61cb0d2c384e5aa852 /gcc/c | |
parent | 7a9f1eed30e169e4d1cfbe4167190db495213406 (diff) | |
download | gcc-f3bede718836610fd741175f4a1b74ba5717e283.zip gcc-f3bede718836610fd741175f4a1b74ba5717e283.tar.gz gcc-f3bede718836610fd741175f4a1b74ba5717e283.tar.bz2 |
re PR c/51849 (-Wc99-compat would be considered useful)
PR c/51849
gcc/
* gcc/doc/invoke.texi: Document -Wc90-c99-compat.
gcc/c-family/
* c-opts.c (sanitize_cpp_opts): Pass warn_c90_c99_compat to libcpp.
* c.opt (Wc90-c99-compat): Add option.
gcc/c/
* c-decl.c (build_array_declarator): Remove check for !flag_isoc99.
Call pedwarn_c90 instead of pedwarn.
(check_bitfield_type_and_width): Likewise.
(declspecs_add_qual): Likewise.
(declspecs_add_type): Likewise.
(warn_variable_length_array): Unify function for -pedantic and -Wvla.
Adjust to only call pedwarn_c90.
(grokdeclarator): Remove pedantic && !flag_isoc99 check. Call
pedwarn_c90 instead of pedwarn.
* c-errors.c (pedwarn_c90): Handle -Wc90-c99-compat.
* c-parser.c (disable_extension_diagnostics): Handle
warn_c90_c99_compat.
(restore_extension_diagnostics): Likewise.
(c_parser_enum_specifier): Remove check for !flag_isoc99. Call
pedwarn_c90 instead of pedwarn.
(c_parser_initelt): Likewise.
(c_parser_postfix_expression): Likewise.
(c_parser_postfix_expression_after_paren_type): Likewise.
(c_parser_compound_statement_nostart): Remove check for !flag_isoc99.
* c-tree.h: Fix formatting.
* c-typeck.c (build_array_ref): Remove check for !flag_isoc99. Call
pedwarn_c90 instead of pedwarn.
gcc/testsuite/
* gcc.dg/Wc90-c99-compat-1.c: New test.
* gcc.dg/Wc90-c99-compat-2.c: New test.
* gcc.dg/Wc90-c99-compat-3.c: New test.
* gcc.dg/Wc90-c99-compat-4.c: New test.
* gcc.dg/Wc90-c99-compat-5.c: New test.
* gcc.dg/Wc90-c99-compat-6.c: New test.
* gcc.dg/wvla-1.c: Adjust dg-warning.
* gcc.dg/wvla-2.c: Adjust dg-warning.
* gcc.dg/wvla-4.c: Adjust dg-warning.
* gcc.dg/wvla-6.c: Adjust dg-warning.
libcpp/
* lex.c (_cpp_lex_direct): Warn when -Wc90-c99-compat is in effect.
* charset.c (_cpp_valid_ucn): Likewise.
* include/cpplib.h (cpp_options): Add cpp_warn_c90_c99_compat.
* macro.c (replace_args): Warn when -Wc90-c99-compat is in effect.
(parse_params): Likewise.
From-SVN: r213786
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 26 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 112 | ||||
-rw-r--r-- | gcc/c/c-errors.c | 33 | ||||
-rw-r--r-- | gcc/c/c-parser.c | 35 | ||||
-rw-r--r-- | gcc/c/c-tree.h | 6 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 9 |
6 files changed, 117 insertions, 104 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 3dcd81f..154768b 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,29 @@ +2014-08-10 Marek Polacek <polacek@redhat.com> + + PR c/51849 + * c-decl.c (build_array_declarator): Remove check for !flag_isoc99. + Call pedwarn_c90 instead of pedwarn. + (check_bitfield_type_and_width): Likewise. + (declspecs_add_qual): Likewise. + (declspecs_add_type): Likewise. + (warn_variable_length_array): Unify function for -pedantic and -Wvla. + Adjust to only call pedwarn_c90. + (grokdeclarator): Remove pedantic && !flag_isoc99 check. Call + pedwarn_c90 instead of pedwarn. + * c-errors.c (pedwarn_c90): Handle -Wc90-c99-compat. + * c-parser.c (disable_extension_diagnostics): Handle + warn_c90_c99_compat. + (restore_extension_diagnostics): Likewise. + (c_parser_enum_specifier): Remove check for !flag_isoc99. Call + pedwarn_c90 instead of pedwarn. + (c_parser_initelt): Likewise. + (c_parser_postfix_expression): Likewise. + (c_parser_postfix_expression_after_paren_type): Likewise. + (c_parser_compound_statement_nostart): Remove check for !flag_isoc99. + * c-tree.h: Fix formatting. + * c-typeck.c (build_array_ref): Remove check for !flag_isoc99. Call + pedwarn_c90 instead of pedwarn. + 2014-08-07 Trevor Saunders <tsaunders@mozilla.com> * c-typeck.c: Remove include of pointer-set.h. diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 050ddff..7ba35bf 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -3968,16 +3968,13 @@ build_array_declarator (location_t loc, } declarator->u.array.static_p = static_p; declarator->u.array.vla_unspec_p = vla_unspec_p; - if (!flag_isoc99) - { - if (static_p || quals != NULL) - pedwarn (loc, OPT_Wpedantic, + if (static_p || quals != NULL) + pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support %<static%> or type " "qualifiers in parameter array declarators"); - if (vla_unspec_p) - pedwarn (loc, OPT_Wpedantic, + if (vla_unspec_p) + pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support %<[*]%> array declarators"); - } if (vla_unspec_p) { if (!current_scope->parm_flag) @@ -4891,10 +4888,9 @@ check_bitfield_type_and_width (tree *type, tree *width, tree orig_name) if (!in_system_header_at (input_location) && type_mv != integer_type_node && type_mv != unsigned_type_node - && type_mv != boolean_type_node - && !flag_isoc99) - pedwarn (input_location, OPT_Wpedantic, - "type of bit-field %qs is a GCC extension", name); + && type_mv != boolean_type_node) + pedwarn_c90 (input_location, OPT_Wpedantic, + "type of bit-field %qs is a GCC extension", name); max_width = TYPE_PRECISION (*type); @@ -4925,52 +4921,27 @@ static void warn_variable_length_array (tree name, tree size) { int const_size = TREE_CONSTANT (size); + enum opt_code opt = (warn_vla == -1 && !warn_c90_c99_compat) + ? OPT_Wpedantic : OPT_Wvla; - if (!flag_isoc99 && pedantic && warn_vla != 0) + if (const_size) { - if (const_size) - { - if (name) - pedwarn (input_location, OPT_Wvla, + if (name) + pedwarn_c90 (input_location, opt, "ISO C90 forbids array %qE whose size " - "can%'t be evaluated", - name); - else - pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array whose size " - "can%'t be evaluated"); - } + "can%'t be evaluated", name); else - { - if (name) - pedwarn (input_location, OPT_Wvla, - "ISO C90 forbids variable length array %qE", - name); - else - pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array"); - } + pedwarn_c90 (input_location, opt, "ISO C90 forbids array " + "whose size can%'t be evaluated"); } - else if (warn_vla > 0) + else { - if (const_size) - { - if (name) - warning (OPT_Wvla, - "the size of array %qE can" - "%'t be evaluated", name); - else - warning (OPT_Wvla, - "the size of array can %'t be evaluated"); - } + if (name) + pedwarn_c90 (input_location, opt, + "ISO C90 forbids variable length array %qE", name); else - { - if (name) - warning (OPT_Wvla, - "variable length array %qE is used", - name); - else - warning (OPT_Wvla, - "variable length array is used"); - } + pedwarn_c90 (input_location, opt, "ISO C90 forbids variable " + "length array"); } } @@ -5186,18 +5157,14 @@ grokdeclarator (const struct c_declarator *declarator, as2 = TYPE_ADDR_SPACE (element_type); address_space = ADDR_SPACE_GENERIC_P (as1)? as2 : as1; - if (pedantic && !flag_isoc99) - { - if (constp > 1) - pedwarn (loc, OPT_Wpedantic, "duplicate %<const%>"); - if (restrictp > 1) - pedwarn (loc, OPT_Wpedantic, "duplicate %<restrict%>"); - if (volatilep > 1) - pedwarn (loc, OPT_Wpedantic, "duplicate %<volatile%>"); - if (atomicp > 1) - pedwarn (loc, OPT_Wpedantic, "duplicate %<_Atomic%>"); - - } + if (constp > 1) + pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<const%>"); + if (restrictp > 1) + pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<restrict%>"); + if (volatilep > 1) + pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<volatile%>"); + if (atomicp > 1) + pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<_Atomic%>"); if (!ADDR_SPACE_GENERIC_P (as1) && !ADDR_SPACE_GENERIC_P (as2) && as1 != as2) error_at (loc, "conflicting named address spaces (%s vs %s)", @@ -5602,10 +5569,9 @@ grokdeclarator (const struct c_declarator *declarator, flexible_array_member = (t->kind == cdk_id); } if (flexible_array_member - && pedantic && !flag_isoc99 && !in_system_header_at (input_location)) - pedwarn (loc, OPT_Wpedantic, - "ISO C90 does not support flexible array members"); + pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not " + "support flexible array members"); /* ISO C99 Flexible array members are effectively identical to GCC's zero-length array extension. */ @@ -9136,8 +9102,8 @@ declspecs_add_qual (source_location loc, default: gcc_unreachable (); } - if (dupe && !flag_isoc99) - pedwarn (loc, OPT_Wpedantic, "duplicate %qE", qual); + if (dupe) + pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %qE", qual); return specs; } @@ -9381,9 +9347,9 @@ declspecs_add_type (location_t loc, struct c_declspecs *specs, break; case RID_COMPLEX: dupe = specs->complex_p; - if (!flag_isoc99 && !in_system_header_at (loc)) - pedwarn (loc, OPT_Wpedantic, - "ISO C90 does not support complex types"); + if (!in_system_header_at (loc)) + pedwarn_c90 (loc, OPT_Wpedantic, + "ISO C90 does not support complex types"); if (specs->typespec_word == cts_auto_type) error_at (loc, ("both %<complex%> and %<__auto_type%> in " @@ -9599,9 +9565,9 @@ declspecs_add_type (location_t loc, struct c_declspecs *specs, } return specs; case RID_BOOL: - if (!flag_isoc99 && !in_system_header_at (loc)) - pedwarn (loc, OPT_Wpedantic, - "ISO C90 does not support boolean types"); + if (!in_system_header_at (loc)) + pedwarn_c90 (loc, OPT_Wpedantic, + "ISO C90 does not support boolean types"); if (specs->long_p) error_at (loc, ("both %<long%> and %<_Bool%> in " diff --git a/gcc/c/c-errors.c b/gcc/c/c-errors.c index 92136e7..5a95b88 100644 --- a/gcc/c/c-errors.c +++ b/gcc/c/c-errors.c @@ -44,21 +44,38 @@ pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...) va_end (ap); } -/* Issue an ISO C90 pedantic warning MSGID. This function is supposed to - be used for matters that are allowed in ISO C99 but not supported in - ISO C90, thus we explicitly don't pedwarn when C99 is specified. - (There is no flag_c90.) */ +/* Issue an ISO C90 pedantic warning MSGID if -pedantic outside C99 mode, + otherwise issue warning MSGID if -Wc90-c99-compat is specified, or if + a specific option such as -Wlong-long is specified. + This function is supposed to be used for matters that are allowed in + ISO C99 but not supported in ISO C90, thus we explicitly don't pedwarn + when C99 is specified. (There is no flag_c90.) */ void pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...) { diagnostic_info diagnostic; va_list ap; + bool warned = false; va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, location, - flag_isoc99 ? DK_WARNING : DK_PEDWARN); - diagnostic.option_index = opt; - report_diagnostic (&diagnostic); + if (pedantic && !flag_isoc99) + { + diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_PEDWARN); + diagnostic.option_index = opt; + warned = report_diagnostic (&diagnostic); + } + else if (opt != OPT_Wpedantic) + { + diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_WARNING); + diagnostic.option_index = opt; + warned = report_diagnostic (&diagnostic); + } + if (warn_c90_c99_compat && !warned) + { + diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_WARNING); + diagnostic.option_index = OPT_Wc90_c99_compat; + report_diagnostic (&diagnostic); + } va_end (ap); } diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index e32bf04..ca8577c 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1072,7 +1072,8 @@ disable_extension_diagnostics (void) | (flag_iso << 3) | (warn_long_long << 4) | (warn_cxx_compat << 5) - | (warn_overlength_strings << 6)); + | (warn_overlength_strings << 6) + | (warn_c90_c99_compat << 7)); cpp_opts->cpp_pedantic = pedantic = 0; warn_pointer_arith = 0; cpp_opts->cpp_warn_traditional = warn_traditional = 0; @@ -1080,6 +1081,7 @@ disable_extension_diagnostics (void) cpp_opts->cpp_warn_long_long = warn_long_long = 0; warn_cxx_compat = 0; warn_overlength_strings = 0; + warn_c90_c99_compat = 0; return ret; } @@ -1096,6 +1098,7 @@ restore_extension_diagnostics (int flags) cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1; warn_cxx_compat = (flags >> 5) & 1; warn_overlength_strings = (flags >> 6) & 1; + warn_c90_c99_compat = (flags >> 7) & 1; } /* Possibly kinds of declarator to parse. */ @@ -2545,8 +2548,9 @@ c_parser_enum_specifier (c_parser *parser) } if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) { - if (seen_comma && !flag_isoc99) - pedwarn (comma_loc, OPT_Wpedantic, "comma at end of enumerator list"); + if (seen_comma) + pedwarn_c90 (comma_loc, OPT_Wpedantic, + "comma at end of enumerator list"); c_parser_consume_token (parser); break; } @@ -4348,9 +4352,9 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) { if (c_parser_next_token_is (parser, CPP_EQ)) { - if (!flag_isoc99) - pedwarn (des_loc, OPT_Wpedantic, - "ISO C90 forbids specifying subobject to initialize"); + pedwarn_c90 (des_loc, OPT_Wpedantic, + "ISO C90 forbids specifying subobject " + "to initialize"); c_parser_consume_token (parser); } else @@ -4566,10 +4570,9 @@ c_parser_compound_statement_nostart (c_parser *parser) c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL, vNULL); if (last_stmt) - pedwarn_c90 (loc, - (pedantic && !flag_isoc99) - ? OPT_Wpedantic - : OPT_Wdeclaration_after_statement, + pedwarn_c90 (loc, (pedantic && !flag_isoc99) + ? OPT_Wpedantic + : OPT_Wdeclaration_after_statement, "ISO C90 forbids mixed declarations and code"); last_stmt = false; } @@ -4598,8 +4601,8 @@ c_parser_compound_statement_nostart (c_parser *parser) restore_extension_diagnostics (ext); if (last_stmt) pedwarn_c90 (loc, (pedantic && !flag_isoc99) - ? OPT_Wpedantic - : OPT_Wdeclaration_after_statement, + ? OPT_Wpedantic + : OPT_Wdeclaration_after_statement, "ISO C90 forbids mixed declarations and code"); last_stmt = false; } @@ -7401,9 +7404,8 @@ c_parser_postfix_expression (c_parser *parser) expr.value = error_mark_node; break; } - if (!flag_isoc99) - pedwarn (loc, OPT_Wpedantic, - "ISO C90 does not support complex types"); + pedwarn_c90 (loc, OPT_Wpedantic, + "ISO C90 does not support complex types"); expr.value = build2 (COMPLEX_EXPR, build_complex_type (TYPE_MAIN_VARIANT @@ -7607,8 +7609,7 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser, type = error_mark_node; } - if (!flag_isoc99) - pedwarn (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals"); + pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals"); non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR) ? CONSTRUCTOR_NON_CONST (init.value) : init.original_code == C_MAYBE_CONST_EXPR); diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index f97d0d5..55e71dc 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -676,7 +676,9 @@ extern tree c_omp_reduction_lookup (tree, tree); extern tree c_check_omp_declare_reduction_r (tree *, int *, void *); /* In c-errors.c */ -extern void pedwarn_c90 (location_t, int opt, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); -extern void pedwarn_c99 (location_t, int opt, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); +extern void pedwarn_c90 (location_t, int opt, const char *, ...) + ATTRIBUTE_GCC_DIAG(3,4); +extern void pedwarn_c99 (location_t, int opt, const char *, ...) + ATTRIBUTE_GCC_DIAG(3,4); #endif /* ! GCC_C_TREE_H */ diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index f8a2316..0ed92c6 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -2510,7 +2510,7 @@ build_array_ref (location_t loc, tree array, tree index) return error_mark_node; } - if (pedantic) + if (pedantic || warn_c90_c99_compat) { tree foo = array; while (TREE_CODE (foo) == COMPONENT_REF) @@ -2518,9 +2518,10 @@ build_array_ref (location_t loc, tree array, tree index) if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo)) pedwarn (loc, OPT_Wpedantic, "ISO C forbids subscripting %<register%> array"); - else if (!flag_isoc99 && !lvalue_p (foo)) - pedwarn (loc, OPT_Wpedantic, - "ISO C90 forbids subscripting non-lvalue array"); + else if (!lvalue_p (foo)) + pedwarn_c90 (loc, OPT_Wpedantic, + "ISO C90 forbids subscripting non-lvalue " + "array"); } type = TREE_TYPE (TREE_TYPE (array)); |