[hackers] [scc] Add warning about empty parameter declarations || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 11 Jan 2016 10:17:13 +0100 (CET)

commit 401f843e3fd7dd3399a30d79b1a35f1340909dbe
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sun Jan 10 15:50:52 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_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
_AT_@ -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)
 {
_AT_@ -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:
_AT_@ -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;
 }
 
_AT_@ -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)
 {
Received on Mon Jan 11 2016 - 10:17:13 CET

This archive was generated by hypermail 2.3.0 : Mon Jan 11 2016 - 10:24:17 CET