There is a missed opportunity here to issue spelling diagnostics
in prototype declarations (e.g., for “extern int foo (int32t);”).

gcc/

        * doc/invoke.texi (Warning Options): Document changes.

gcc/c/

        * c-decl.cc (warn_defaults_to): Call emit_diagnostic_valist
        instead of reimplementing it. Issue a pedpermerror for C99
        and later.
        (store_parm_decls_oldstyle): Call pedpermerror for
        OPT_Wimplicit_int.

gcc/testsuite/

        * 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                             | 20 +++++++++++---------
 gcc/doc/invoke.texi                         |  7 +++++--
 gcc/testsuite/gcc.dg/Wimplicit-int-1.c      |  2 +-
 gcc/testsuite/gcc.dg/Wimplicit-int-1a.c     | 11 +++++++++++
 gcc/testsuite/gcc.dg/Wimplicit-int-4.c      |  2 +-
 gcc/testsuite/gcc.dg/Wimplicit-int-4a.c     | 11 +++++++++++
 gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c  |  2 +-
 gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c  | 17 +++++++++++++++++
 gcc/testsuite/gcc.dg/noncompile/pr79758-2.c |  6 ++++++
 gcc/testsuite/gcc.dg/noncompile/pr79758.c   |  1 +
 gcc/testsuite/gcc.dg/pr105635-2.c           | 11 +++++++++++
 gcc/testsuite/gcc.dg/pr105635.c             |  2 +-
 12 files changed, 77 insertions(+), 15 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Wimplicit-int-1a.c
 create mode 100644 gcc/testsuite/gcc.dg/Wimplicit-int-4a.c
 create mode 100644 gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c
 create mode 100644 gcc/testsuite/gcc.dg/noncompile/pr79758-2.c
 create mode 100644 gcc/testsuite/gcc.dg/pr105635-2.c

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index e8387bfa984..f787d213cfe 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -6577,16 +6577,18 @@ warn_defaults_to (location_t location, int opt, const 
char *gmsgid, ...)
 {
   diagnostic_info diagnostic;
   va_list ap;
-  rich_location richloc (line_table, location);
+  diagnostic_t kind;
 
   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);
+  if (flag_isoc99 && !flag_pedantic_errors && opt)
+    kind = DK_PERMERROR;
+  else if (flag_isoc99)
+    kind = DK_PEDWARN;
+  else
+    kind = DK_WARNING;
+  emit_diagnostic_valist (kind, location, opt, gmsgid, &ap);
   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.  */
@@ -10635,9 +10637,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);
+           pedpermerror (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 1a15af29f01..3a1b9b00f24 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6180,6 +6180,7 @@ that have their own flag:
 
 @gccoptlist{
 -Wimplicit-function-declaration @r{(C)}
+-Wimplicit-int @r{(C)}
 -Wint-conversion @r{(C)}
 -Wnarrowing @r{(C++)}
 }
@@ -6851,8 +6852,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 4a96e8f505d..fc7726c517e 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 00000000000..ef1835e2d3a
--- /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 c9c6e8e5e95..99c61a76ecf 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 00000000000..920a088f02b
--- /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 ba60f7a095a..8943534f2b2 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 00000000000..d73d6a3cfa8
--- /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 00000000000..e6a27f952ef
--- /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 a31216068f0..e42a44380fa 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/pr105635-2.c 
b/gcc/testsuite/gcc.dg/pr105635-2.c
new file mode 100644
index 00000000000..807eef0b7cd
--- /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 aa02f593bfa..b98ea1b3c3b 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" } */
 
-- 
2.41.0


Reply via email to