diff options
author | Marek Polacek <polacek@redhat.com> | 2014-08-19 06:04:38 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2014-08-19 06:04:38 +0000 |
commit | 35aff4fb82ce0f615dc5e0ad73341a1fe77cbd12 (patch) | |
tree | 252dbb8b85e09aa8d379abb28ffc5e483fa4edb2 /gcc/c/c-decl.c | |
parent | fdec323d35ab9bf489e374c0545621bc90dd08c0 (diff) | |
download | gcc-35aff4fb82ce0f615dc5e0ad73341a1fe77cbd12.zip gcc-35aff4fb82ce0f615dc5e0ad73341a1fe77cbd12.tar.gz gcc-35aff4fb82ce0f615dc5e0ad73341a1fe77cbd12.tar.bz2 |
invoke.texi: Document -Wc99-c11-compat.
* doc/invoke.texi: Document -Wc99-c11-compat.
c-family/
* c.opt (Wc99-c11-compat): New option.
c/
* c-decl.c (diagnose_mismatched_decls): Unconditionally call
pedwarn_c99 instead of pedwarn.
(grokfield): Likewise.
(warn_defaults_to): New function.
(grokdeclarator): Call warn_defaults_to instead of pedwarn_c99.
Unconditionally call pedwarn_c99 instead of pedwarn.
(start_function): Call warn_defaults_to instead of pedwarn_c99.
(declspecs_add_scspec): Call pedwarn_c99 instead of pedwarn, don't
check flag_isoc11 before.
* c-errors.c (pedwarn_c99): Change the return type to bool.
Handle -Wc99-c11-compat.
* c-parser.c (disable_extension_diagnostics): Handle
warn_c99_c11_compat.
(restore_extension_diagnostics): Likewise.
(c_parser_static_assert_declaration_no_semi): Call pedwarn_c99
instead of pedwarn, don't check flag_isoc11 before.
(c_parser_declspecs): Likewise.
(c_parser_alignas_specifier): Likewise.
(c_parser_alignof_expression): Likewise.
(c_parser_generic_selection): Likewise.
* c-tree.h (pedwarn_c99): Update declaration.
* c-typeck.c (c_finish_return): Call pedwarn or warning_at instead
of pedwarn_c99.
testsuite/
* gcc.dg/Wc99-c11-compat-1.c: New test.
* gcc.dg/Wc99-c11-compat-2.c: New test.
* gcc.dg/Wc99-c11-compat-3.c: New test.
* gcc.dg/Wc99-c11-compat-4.c: New test.
* gcc.dg/Wc99-c11-compat-5.c: New test.
* gcc.dg/Wc99-c11-compat-6.c: New test.
* gcc.dg/Wc99-c11-compat-7.c: New test.
From-SVN: r214133
Diffstat (limited to 'gcc/c/c-decl.c')
-rw-r--r-- | gcc/c/c-decl.c | 76 |
1 files changed, 43 insertions, 33 deletions
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 138b014..ec0d0ef 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -538,6 +538,8 @@ static tree grokdeclarator (const struct c_declarator *, bool *, enum deprecated_states); static tree grokparms (struct c_arg_info *, bool); static void layout_array_type (tree); +static void warn_defaults_to (location_t, int, const char *, ...) + ATTRIBUTE_GCC_DIAG(3,4); /* T is a statement. Add it to the statement-tree. This is the C/ObjC version--C++ has a slightly different version of this @@ -1844,12 +1846,9 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, newdecl); locate_old_decl (olddecl); } - else if (pedantic && !flag_isoc11) - { - pedwarn (input_location, OPT_Wpedantic, - "redefinition of typedef %q+D", newdecl); - locate_old_decl (olddecl); - } + else if (pedwarn_c99 (input_location, OPT_Wpedantic, + "redefinition of typedef %q+D", newdecl)) + locate_old_decl (olddecl); return true; } @@ -4941,6 +4940,22 @@ warn_variable_length_array (tree name, tree size) } } +/* Print warning about defaulting to int if necessary. */ + +static void +warn_defaults_to (location_t location, int opt, const char *gmsgid, ...) +{ + diagnostic_info diagnostic; + va_list ap; + + va_start (ap, gmsgid); + diagnostic_set_info (&diagnostic, gmsgid, &ap, location, + flag_isoc99 ? DK_PEDWARN : DK_WARNING); + diagnostic.option_index = opt; + report_diagnostic (&diagnostic); + va_end (ap); +} + /* Given declspecs and a declarator, determine the name and type of the object declared and construct a ..._DECL node for it. @@ -5117,12 +5132,12 @@ grokdeclarator (const struct c_declarator *declarator, else { if (name) - pedwarn_c99 (loc, flag_isoc99 ? 0 : OPT_Wimplicit_int, - "type defaults to %<int%> in declaration of %qE", - name); + warn_defaults_to (loc, flag_isoc99 ? 0 : OPT_Wimplicit_int, + "type defaults to %<int%> in declaration " + "of %qE", name); else - pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int, - "type defaults to %<int%> in type name"); + warn_defaults_to (loc, flag_isoc99 ? 0 : OPT_Wimplicit_int, + "type defaults to %<int%> in type name"); } } @@ -6249,15 +6264,12 @@ grokdeclarator (const struct c_declarator *declarator, DECL_DECLARED_INLINE_P (decl) = 1; if (declspecs->noreturn_p) { - if (!flag_isoc11) - { - if (flag_isoc99) - pedwarn (loc, OPT_Wpedantic, + if (flag_isoc99) + pedwarn_c99 (loc, OPT_Wpedantic, "ISO C99 does not support %<_Noreturn%>"); - else - pedwarn (loc, OPT_Wpedantic, + else + pedwarn_c99 (loc, OPT_Wpedantic, "ISO C90 does not support %<_Noreturn%>"); - } TREE_THIS_VOLATILE (decl) = 1; } } @@ -6964,15 +6976,12 @@ grokfield (location_t loc, pedwarn (loc, 0, "declaration does not declare anything"); return NULL_TREE; } - if (!flag_isoc11) - { - if (flag_isoc99) - pedwarn (loc, OPT_Wpedantic, + if (flag_isoc99) + pedwarn_c99 (loc, OPT_Wpedantic, "ISO C99 doesn%'t support unnamed structs/unions"); - else - pedwarn (loc, OPT_Wpedantic, + else + pedwarn_c99 (loc, OPT_Wpedantic, "ISO C90 doesn%'t support unnamed structs/unions"); - } } value = grokdeclarator (declarator, declspecs, FIELD, false, @@ -7913,9 +7922,10 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, } if (warn_about_return_type) - pedwarn_c99 (loc, flag_isoc99 ? 0 - : (warn_return_type ? OPT_Wreturn_type : OPT_Wimplicit_int), - "return type defaults to %<int%>"); + warn_defaults_to (loc, flag_isoc99 ? 0 + : (warn_return_type ? OPT_Wreturn_type + : OPT_Wimplicit_int), + "return type defaults to %<int%>"); /* Make the init_value nonzero so pushdecl knows this is not tentative. error_mark_node is replaced below (in pop_scope) with the BLOCK. */ @@ -9893,14 +9903,14 @@ declspecs_add_scspec (source_location loc, identifier in the implementation namespace; only diagnose it for the C11 spelling because of existing code using the other spelling. */ - if (!flag_isoc11 && !specs->thread_gnu_p) + if (!specs->thread_gnu_p) { if (flag_isoc99) - pedwarn (loc, OPT_Wpedantic, - "ISO C99 does not support %qE", scspec); + pedwarn_c99 (loc, OPT_Wpedantic, + "ISO C99 does not support %qE", scspec); else - pedwarn (loc, OPT_Wpedantic, - "ISO C90 does not support %qE", scspec); + pedwarn_c99 (loc, OPT_Wpedantic, + "ISO C90 does not support %qE", scspec); } specs->locations[cdw_thread] = loc; } |