commit 401f843e3fd7dd3399a30d79b1a35f1340909dbe
parent 01d01a1a25cb16603479e6e0a7ae3dbc7c726686
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 10 Jan 2016 15:50:52 +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.
Diffstat:
M | cc1/decl.c | | | 41 | +++++++++++++++++++---------------------- |
1 file changed, 19 insertions(+), 22 deletions(-)
diff --git 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)
{