shithub: scc

Download patch

ref: 401f843e3fd7dd3399a30d79b1a35f1340909dbe
parent: 01d01a1a25cb16603479e6e0a7ae3dbc7c726686
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Jan 10 10:50:52 EST 2016

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.

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -116,6 +116,23 @@
 	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 @@
 	TINT n = funtp->n.elem;
 	char *name = sym->name;
 
-	sym->type = tp;
-
 	switch (dcl->sclass) {
 	case STATIC:
 	case EXTERN:
@@ -157,16 +172,15 @@
 		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;
 }
 
@@ -533,23 +547,6 @@
 	sym->type = dcl->type;
 
 	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 *