commit 401f843e3fd7dd3399a30d79b1a35f1340909dbe
Author:     Roberto E. Vargas Caballero <k...@shike2.com>
AuthorDate: Sun Jan 10 15:50:52 2016 +0100
Commit:     Roberto E. Vargas Caballero <k...@shike2.com>
CommitDate: Sun Jan 10 15:50:52 2016 +0100

    Add warning about empty parameter declarations
    
    This is an extension of scc over c99, where we allow to have empty
    declarations in parameters but it is a good idea tt give a
    warning to the user in this case.

diff --git a/cc1/decl.c b/cc1/decl.c
index 7b7ff2d..7f2e96f 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -116,6 +116,23 @@ arydcl(struct declarators *dp)
        push(dp, ARY, n);
 }
 
+static int
+empty(Symbol *sym, Type *tp)
+{
+       if (!sym->name) {
+               sym->type = tp;
+               switch (tp->op) {
+               default:
+                       warn("empty declaration");
+               case STRUCT:
+               case UNION:
+               case ENUM:
+                       return 1;
+               }
+       }
+       return 0;
+}
+
 static Symbol *
 parameter(struct decl *dcl)
 {
@@ -124,8 +141,6 @@ parameter(struct decl *dcl)
        TINT n = funtp->n.elem;
        char *name = sym->name;
 
-       sym->type = tp;
-
        switch (dcl->sclass) {
        case STATIC:
        case EXTERN:
@@ -157,16 +172,15 @@ parameter(struct decl *dcl)
                errorp("incorrect function type for a function parameter");
                return NULL;
        }
-
-       if (name) {
+       if (!empty(sym, tp)) {
                if ((sym = install(NS_IDEN, sym)) == NULL) {
                        errorp("redefinition of parameter '%s'", name);
                        return NULL;
                }
        }
+
        sym->type = tp;
        sym->flags |= ISUSED;    /* avoid non used warnings in prototypes */
-
        return sym;
 }
 
@@ -535,23 +549,6 @@ type(struct decl *dcl)
        return sym;
 }
 
-static int
-empty(Symbol *sym, Type *tp)
-{
-       if (!sym->name) {
-               sym->type = tp;
-               switch (tp->op) {
-               default:
-                       warn("empty declaration");
-               case STRUCT:
-               case UNION:
-               case ENUM:
-                       return 1;
-               }
-       }
-       return 0;
-}
-
 static Symbol *
 field(struct decl *dcl)
 {

Reply via email to