From 4ee2aca7ca098cc6e622a9a41e63224af37e6532 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Fri, 1 Dec 2023 08:10:13 +0100 Subject: c: Turn -Wimplicit-int into a permerror Most of these new permerrors are currently not diagnosed in system headers. gcc/ PR c/91093 PR c/96284 * doc/invoke.texi (Warning Options): Document changes. gcc/c/ * c-decl.cc (warn_defaults_to): Remove. (grok_declarator, start_function): Call permerror_opt instead of warn_defaults_to. (store_parm_decls_oldstyle): Call permerror_opt for OPT_Wimplicit_int. gcc/testsuite/ * gcc.dg/permerror-default.c (implicit_int_1, implicit_int_2) (implicit_int_3, implicit_int_4): Expect new permerror. * gcc.dg/permerror-system.c: Expect a single new permerror. * gcc.dg/Wimplicit-int-1.c: Compile with -fpermissive due to expected warning. * gcc.dg/Wimplicit-int-4.c: Likewise. * gcc.dg/Wimplicit-int-1a.c: New test. Copied from gcc.dg/Wimplicit-int-1.c, but expect errors. * gcc.dg/Wimplicit-int-4a.c: New test. Copied from gcc.dg/Wimplicit-int-4.c, but expect errors. * gcc.dg/gnu23-attr-syntax-2.c: Compile with -fpermissive due to expected implicit-int error. * gcc.dg/gnu23-attr-syntax-3.c: New test. Copied from gcc.dg/gnu23-attr-syntax-2.c, but expect an error. * gcc.dg/pr105635.c: Build with -fpermissive due to implicit int. * gcc.dg/pr105635-2.c: New test. Copied from gcc.dg/pr105635.c. Expect implicit int error. * gcc.dg/noncompile/pr79758.c: Build with -fpermissive due to implicit int. * gcc.dg/noncompile/pr79758-2.c: New test. Copied from gcc.dg/noncompile/pr79758.c. Expect implicit int error. --- gcc/c/c-decl.cc | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) (limited to 'gcc/c') diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 4d17f05..14d66ff 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -647,8 +647,6 @@ 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); static const char *header_for_builtin_fn (tree); /* T is a statement. Add it to the statement-tree. This is the @@ -6576,23 +6574,6 @@ 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; - rich_location richloc (line_table, location); - - va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, - flag_isoc99 ? DK_PEDWARN : DK_WARNING); - diagnostic.option_index = opt; - diagnostic_report_diagnostic (global_dc, &diagnostic); - va_end (ap); -} - /* Returns the smallest location != UNKNOWN_LOCATION in LOCATIONS, considering only those c_declspec_words found in LIST, which must be terminated by cdw_number_of_elements. */ @@ -6881,12 +6862,12 @@ grokdeclarator (const struct c_declarator *declarator, else { if (name) - warn_defaults_to (loc, OPT_Wimplicit_int, - "type defaults to % in declaration " - "of %qE", name); + permerror_opt (loc, OPT_Wimplicit_int, + "type defaults to % in declaration " + "of %qE", name); else - warn_defaults_to (loc, OPT_Wimplicit_int, - "type defaults to % in type name"); + permerror_opt (loc, OPT_Wimplicit_int, + "type defaults to % in type name"); } } @@ -10300,10 +10281,10 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, } if (warn_about_return_type) - warn_defaults_to (loc, flag_isoc99 ? OPT_Wimplicit_int - : (warn_return_type > 0 ? OPT_Wreturn_type - : OPT_Wimplicit_int), - "return type defaults to %"); + permerror_opt (loc, flag_isoc99 ? OPT_Wimplicit_int + : (warn_return_type > 0 ? OPT_Wreturn_type + : OPT_Wimplicit_int), + "return type defaults to %"); /* Make the init_value nonzero so pushdecl knows this is not tentative. error_mark_node is replaced below (in pop_scope) with the BLOCK. */ @@ -10645,9 +10626,9 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) warn_if_shadowing (decl); if (flag_isoc99) - pedwarn (DECL_SOURCE_LOCATION (decl), - OPT_Wimplicit_int, "type of %qD defaults to %", - decl); + permerror_opt (DECL_SOURCE_LOCATION (decl), + OPT_Wimplicit_int, "type of %qD defaults to %", + decl); else warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wmissing_parameter_type, -- cgit v1.1