re PR c/17881 (Incomplete type warning is issued even for prototypes)
authorJoseph Myers <jsm@polyomino.org.uk>
Sun, 10 Oct 2004 19:20:35 +0000 (20:20 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Sun, 10 Oct 2004 19:20:35 +0000 (20:20 +0100)
PR c/17881
* c-decl.c (grokparms): Don't warn for parameters of incomplete
type in declarations that are not definitions except for the case
of parameters of void type.

testsuite:
* parm-incomplete-1.c: New test.

From-SVN: r88850

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/parm-incomplete-1.c [new file with mode: 0644]

index ba5c10c764124ccbdb635018b2d8fd0b909e7cc4..32049a0ae99b790e48cb2672dae6be0823373756 100644 (file)
@@ -1,3 +1,10 @@
+2004-10-10  Joseph S. Myers  <jsm@polyomino.org.uk>
+
+       PR c/17881
+       * c-decl.c (grokparms): Don't warn for parameters of incomplete
+       type in declarations that are not definitions except for the case
+       of parameters of void type.
+
 2004-10-10  Kazu Hirata  <kazu@cs.umass.edu>
 
        * tree-cfg.c: Fix comment typos.
index f2f9a27d7c307edeb52c0c4bd0fd62028c713b55..4d6d24bcb7467587a29c925e78cc901125f29c88 100644 (file)
@@ -4648,10 +4648,14 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
       tree parm, type, typelt;
       unsigned int parmno;
 
-      /* If the arg types are incomplete in a declaration, they must
-        include undefined tags.  These tags can never be defined in
-        the scope of the declaration, so the types can never be
-        completed, and no call can be compiled successfully.  */
+      /* If there is a parameter of incomplete type in a definition,
+        this is an error.  In a declaration this is valid, and a
+        struct or union type may be completed later, before any calls
+        or definition of the function.  In the case where the tag was
+        first declared within the parameter list, a warning has
+        already been given.  If a parameter has void type, then
+        however the function cannot be defined or called, so
+        warn.  */
 
       for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
           parm;
@@ -4675,13 +4679,13 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
                  TREE_VALUE (typelt) = error_mark_node;
                  TREE_TYPE (parm) = error_mark_node;
                }
-             else
+             else if (VOID_TYPE_P (type))
                {
                  if (DECL_NAME (parm))
-                   warning ("%Jparameter %u (%qD) has incomplete type",
+                   warning ("%Jparameter %u (%qD) has void type",
                             parm, parmno, parm);
                  else
-                   warning ("%Jparameter %u has incomplete type",
+                   warning ("%Jparameter %u has void type",
                             parm, parmno);
                }
            }
index a264cc0f424d5fc5198cce0f1db3bbe8f13b5773..28a26b2eb76542eb392f8a9c3ff3dcfd3345f8ea 100644 (file)
@@ -1,3 +1,8 @@
+2004-10-10  Joseph S. Myers  <jsm@polyomino.org.uk>
+
+       PR c/17881
+       * parm-incomplete-1.c: New test.
+
 2004-10-09  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/17867
diff --git a/gcc/testsuite/gcc.dg/parm-incomplete-1.c b/gcc/testsuite/gcc.dg/parm-incomplete-1.c
new file mode 100644 (file)
index 0000000..3ec713e
--- /dev/null
@@ -0,0 +1,28 @@
+/* Test warnings and errors for incomplete parameter types.  Should
+   not be warned for in declarations that are not definitions: bug
+   17881.  Void types may be a special case, especially for unnamed
+   parameters and when qualified or with a storage class specifier;
+   see C90 6.5.4.3, DR#017 Q14, C90 TC1, DR#157, C99 J.2 (referencing
+   C99 6.7.5.3); the precise rules are unclear.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct s;
+void f (struct s);
+void (*g)(struct s);
+struct t { void (*p)(struct s); };
+
+struct s { int b; };
+void h (struct s x) { }
+
+void j(struct t2); /* { dg-warning "warning: 'struct t2' declared inside parameter list" } */
+/* { dg-warning "its scope is only" "explanation" { target *-*-* } 19 } */
+
+union u;
+
+void v(union u x) { } /* { dg-error "error: parameter 1 \\('x'\\) has incomplete type" } */
+
+void p(void x); /* { dg-warning "warning: parameter 1 \\('x'\\) has void type" } */
+
+void q(const void x); /* { dg-warning "warning: parameter 1 \\('x'\\) has void type" } */