aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2023-12-01 08:10:13 +0100
committerFlorian Weimer <fweimer@redhat.com>2023-12-01 08:10:13 +0100
commit4ee2aca7ca098cc6e622a9a41e63224af37e6532 (patch)
treedeac9afa94a3f81a52057752262f2b565453a84e
parent55e94561e97ed0bce4774aa1c6b5d5d82209a379 (diff)
downloadgcc-4ee2aca7ca098cc6e622a9a41e63224af37e6532.zip
gcc-4ee2aca7ca098cc6e622a9a41e63224af37e6532.tar.gz
gcc-4ee2aca7ca098cc6e622a9a41e63224af37e6532.tar.bz2
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.
-rw-r--r--gcc/c/c-decl.cc43
-rw-r--r--gcc/doc/invoke.texi7
-rw-r--r--gcc/testsuite/gcc.dg/Wimplicit-int-1.c2
-rw-r--r--gcc/testsuite/gcc.dg/Wimplicit-int-1a.c11
-rw-r--r--gcc/testsuite/gcc.dg/Wimplicit-int-4.c2
-rw-r--r--gcc/testsuite/gcc.dg/Wimplicit-int-4a.c11
-rw-r--r--gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c2
-rw-r--r--gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c17
-rw-r--r--gcc/testsuite/gcc.dg/noncompile/pr79758-2.c6
-rw-r--r--gcc/testsuite/gcc.dg/noncompile/pr79758.c1
-rw-r--r--gcc/testsuite/gcc.dg/permerror-default.c12
-rw-r--r--gcc/testsuite/gcc.dg/permerror-system.c2
-rw-r--r--gcc/testsuite/gcc.dg/pr105635-2.c11
-rw-r--r--gcc/testsuite/gcc.dg/pr105635.c2
14 files changed, 86 insertions, 43 deletions
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 %<int%> in declaration "
- "of %qE", name);
+ permerror_opt (loc, OPT_Wimplicit_int,
+ "type defaults to %<int%> in declaration "
+ "of %qE", name);
else
- warn_defaults_to (loc, OPT_Wimplicit_int,
- "type defaults to %<int%> in type name");
+ permerror_opt (loc, OPT_Wimplicit_int,
+ "type defaults to %<int%> 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 %<int%>");
+ permerror_opt (loc, flag_isoc99 ? OPT_Wimplicit_int
+ : (warn_return_type > 0 ? 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. */
@@ -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 %<int%>",
- decl);
+ permerror_opt (DECL_SOURCE_LOCATION (decl),
+ OPT_Wimplicit_int, "type of %qD defaults to %<int%>",
+ decl);
else
warning_at (DECL_SOURCE_LOCATION (decl),
OPT_Wmissing_parameter_type,
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 5244958..51bf19d 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6185,6 +6185,7 @@ that have their own flag:
@gccoptlist{
-Wimplicit-function-declaration @r{(C and Objective-C only)}
+-Wimplicit-int @r{(C and Objective-C only)}
-Wint-conversion @r{(C and Objective-C only)}
-Wnarrowing @r{(C++)}
}
@@ -6856,8 +6857,10 @@ This warning is enabled by @option{-Wall} in C++.
@opindex Wno-implicit-int
@item -Wno-implicit-int @r{(C and Objective-C only)}
This option controls warnings when a declaration does not specify a type.
-This warning is enabled by default in C99 and later dialects of C,
-and also by @option{-Wall}.
+This warning is enabled by default, as an error, in C99 and later
+dialects of C, and also by @option{-Wall}. The error can be downgraded
+to a warning using @option{-fpermissive} (along with certain other
+errors), or for this error alone, with @option{-Wno-error=implicit-int}.
This warning is upgraded to an error by @option{-pedantic-errors}.
diff --git a/gcc/testsuite/gcc.dg/Wimplicit-int-1.c b/gcc/testsuite/gcc.dg/Wimplicit-int-1.c
index 4a96e8f..fc7726c 100644
--- a/gcc/testsuite/gcc.dg/Wimplicit-int-1.c
+++ b/gcc/testsuite/gcc.dg/Wimplicit-int-1.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "" } */
+/* { dg-options "-fpermissive" } */
static l; /* { dg-warning "type defaults to" } */
diff --git a/gcc/testsuite/gcc.dg/Wimplicit-int-1a.c b/gcc/testsuite/gcc.dg/Wimplicit-int-1a.c
new file mode 100644
index 0000000..ef1835e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wimplicit-int-1a.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+static l; /* { dg-error "type defaults to" } */
+
+foo (a) /* { dg-error "return type defaults to" } */
+/* { dg-error "type of .a. defaults to .int." "type" { target *-*-* } .-1 } */
+{
+ auto p; /* { dg-error "type defaults to" } */
+ typedef bar; /* { dg-error "type defaults to" } */
+}
diff --git a/gcc/testsuite/gcc.dg/Wimplicit-int-4.c b/gcc/testsuite/gcc.dg/Wimplicit-int-4.c
index c9c6e8e..99c61a7 100644
--- a/gcc/testsuite/gcc.dg/Wimplicit-int-4.c
+++ b/gcc/testsuite/gcc.dg/Wimplicit-int-4.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-Wno-implicit -Wimplicit-int" } */
+/* { dg-options "-fpermissive -Wno-implicit -Wimplicit-int" } */
static l; /* { dg-warning "type defaults to" } */
diff --git a/gcc/testsuite/gcc.dg/Wimplicit-int-4a.c b/gcc/testsuite/gcc.dg/Wimplicit-int-4a.c
new file mode 100644
index 0000000..920a088
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wimplicit-int-4a.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-Wno-implicit -Wimplicit-int" } */
+
+static l; /* { dg-error "type defaults to" } */
+
+foo (a) /* { dg-error "return type defaults to" } */
+/* { dg-error "type of .a. defaults to .int." "type" { target *-*-* } .-1 } */
+{
+ auto p; /* { dg-error "type defaults to" } */
+ typedef bar; /* { dg-error "type defaults to" } */
+}
diff --git a/gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c b/gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c
index ba60f7a..8943534 100644
--- a/gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c
+++ b/gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c
@@ -1,7 +1,7 @@
/* Test C23 attribute syntax. Invalid uses of attributes with GNU C
features. */
/* { dg-do compile } */
-/* { dg-options "-std=gnu23 -w" } */
+/* { dg-options "-fpermissive -std=gnu23 -w" } */
/* Attributes cannot be used as prefix attributes on old-style
parameter declarations or on function declarators with identifier
diff --git a/gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c b/gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c
new file mode 100644
index 0000000..d73d6a3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c
@@ -0,0 +1,17 @@
+/* Test C23 attribute syntax. Invalid uses of attributes with GNU C
+ features. Non-permissive variant. */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu23 -w" } */
+
+/* Attributes cannot be used as prefix attributes on old-style
+ parameter declarations or on function declarators with identifier
+ lists (removed from C23). */
+
+void (*f(a, b) [[]])() int a, b; { } /* { dg-error "expected" } */
+
+void f(x, y) int x; [[]] int y; { } /* { dg-error "expected" } */
+/* { dg-error "type of 'y' defaults to 'int'" "" { target *-*-* } .-1 } */
+
+/* Nonempty attributes cannot be used as postfix attributes with
+ __auto_type. */
+__auto_type [[gnu::no_such_attr]] x = 1; /* { dg-error "'__auto_type' followed by" } */
diff --git a/gcc/testsuite/gcc.dg/noncompile/pr79758-2.c b/gcc/testsuite/gcc.dg/noncompile/pr79758-2.c
new file mode 100644
index 0000000..e6a27f9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/noncompile/pr79758-2.c
@@ -0,0 +1,6 @@
+/* PR c/79758 */
+/* { dg-do compile } */
+
+void fn1 (int[a]) { }; /* { dg-error "undeclared here" } */
+void fn1 (b) { }; /* { dg-error "redefinition" } */
+/* { dg-error "defaults to 'int'" "" { target *-*-* } .-1 } */
diff --git a/gcc/testsuite/gcc.dg/noncompile/pr79758.c b/gcc/testsuite/gcc.dg/noncompile/pr79758.c
index a312160..e42a443 100644
--- a/gcc/testsuite/gcc.dg/noncompile/pr79758.c
+++ b/gcc/testsuite/gcc.dg/noncompile/pr79758.c
@@ -1,5 +1,6 @@
/* PR c/79758 */
/* { dg-do compile } */
+/* { dg-additional-options "-fpermissive" } */
void fn1 (int[a]) { }; /* { dg-error "undeclared here" } */
void fn1 (b) { }; /* { dg-error "redefinition" } */
diff --git a/gcc/testsuite/gcc.dg/permerror-default.c b/gcc/testsuite/gcc.dg/permerror-default.c
index f37f918..90f2220 100644
--- a/gcc/testsuite/gcc.dg/permerror-default.c
+++ b/gcc/testsuite/gcc.dg/permerror-default.c
@@ -10,13 +10,13 @@ implicit_function_declaration (void)
f1 (); /* { dg-error "'f1' \\\[-Wimplicit-function-declaration\\\]" } */
}
-extern implicit_int_1; /* { dg-warning "'implicit_int_1' \\\[-Wimplicit-int\\\]" } */
-typedef implicit_int_2; /* { dg-warning "'implicit_int_2' \\\[-Wimplicit-int\\\]" } */
-extern implicit_int_3 (void); /* { dg-warning "'implicit_int_3' \\\[-Wimplicit-int\\]" } */
-implicit_int_4 (i) /* { dg-warning "return type defaults to 'int' \\\[-Wimplicit-int\\\]" } */
-/* { dg-warning "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} .-1 } */
+extern implicit_int_1; /* { dg-error "'implicit_int_1' \\\[-Wimplicit-int\\\]" } */
+typedef implicit_int_2; /* { dg-error "'implicit_int_2' \\\[-Wimplicit-int\\\]" } */
+extern implicit_int_3 (void); /* { dg-error "'implicit_int_3' \\\[-Wimplicit-int\\]" } */
+implicit_int_4 (i) /* { dg-error "return type defaults to 'int' \\\[-Wimplicit-int\\\]" } */
+/* { dg-error "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} .-1 } */
{
- (const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
+ (const) 0; /* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
}
extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
diff --git a/gcc/testsuite/gcc.dg/permerror-system.c b/gcc/testsuite/gcc.dg/permerror-system.c
index e4da4a9..60c65ff 100644
--- a/gcc/testsuite/gcc.dg/permerror-system.c
+++ b/gcc/testsuite/gcc.dg/permerror-system.c
@@ -10,6 +10,8 @@
/* { dg-error "'f1' \\\[-Wimplicit-function-declaration\\\]" "" { target *-*-* } 10 } */
+/* { dg-error "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} 16 } */
+
/* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" "" { target *-*-* } 29 } */
/* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" "" { target *-*-* } 30 } */
/* { dg-error "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 31 } */
diff --git a/gcc/testsuite/gcc.dg/pr105635-2.c b/gcc/testsuite/gcc.dg/pr105635-2.c
new file mode 100644
index 0000000..807eef0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr105635-2.c
@@ -0,0 +1,11 @@
+/* PR c/105635 */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+void foo (int, int[*]); /* { dg-message "previous declaration of 'foo' with type" } */
+
+foo (int x, int y) /* { dg-error "return type defaults to 'int'" } */
+{ /* { dg-warning "conflicting types for 'foo'" "" { target *-*-* } .-1 } */
+ /* { dg-message "declared here" "" { target *-*-* } .-2 } */
+ return (x >= 0) != (y < 0); /* { dg-warning "'return' with a value, in function returning void" } */
+}
diff --git a/gcc/testsuite/gcc.dg/pr105635.c b/gcc/testsuite/gcc.dg/pr105635.c
index aa02f59..b98ea1b 100644
--- a/gcc/testsuite/gcc.dg/pr105635.c
+++ b/gcc/testsuite/gcc.dg/pr105635.c
@@ -1,6 +1,6 @@
/* PR c/105635 */
/* { dg-do compile } */
-/* { dg-options "-Wall" } */
+/* { dg-options "-fpermissive -Wall" } */
void foo (int, int[*]); /* { dg-message "previous declaration of 'foo' with type" } */