From: eck Date: Fri, 2 Nov 1990 09:23:27 +0000 (+0000) Subject: added warning about old-fashioned declarations X-Git-Tag: release-5-5~1448 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=d7c15759ee270c63db9b5679dd4980e4d551636a;p=ack.git added warning about old-fashioned declarations cleaned up error reporting changed implicit declaration handling --- diff --git a/lang/cem/cemcom.ansi/ch3.c b/lang/cem/cemcom.ansi/ch3.c index 97d65c58d..14135e21d 100644 --- a/lang/cem/cemcom.ansi/ch3.c +++ b/lang/cem/cemcom.ansi/ch3.c @@ -341,7 +341,7 @@ ch3cast(expp, oper, tp) if (oldtp->tp_fund == POINTER && is_integral_type(tp)) { /* from pointer to integral */ if (oper != CAST) - expr_warning(exp, + expr_strict(exp, "illegal conversion of pointer to %s", symbol2str(tp->tp_fund)); if (oldtp->tp_size > tp->tp_size) @@ -367,7 +367,7 @@ ch3cast(expp, oper, tp) if (is_cp_cst(exp) && exp->VL_VALUE == (arith)0) break; default: - expr_warning(exp, + expr_strict(exp, "illegal conversion of %s to pointer", symbol2str(oldtp->tp_fund)); break; @@ -388,7 +388,7 @@ ch3cast(expp, oper, tp) } else if (oldtp->tp_size == tp->tp_size && oper == CAST) { - expr_warning(exp, "dubious conversion based on equal size"); + expr_strict(exp, "dubious conversion based on equal size"); exp->ex_type = tp; /* brute force */ } else { diff --git a/lang/cem/cemcom.ansi/code.c b/lang/cem/cemcom.ansi/code.c index 8f6779fbe..962873c24 100644 --- a/lang/cem/cemcom.ansi/code.c +++ b/lang/cem/cemcom.ansi/code.c @@ -186,7 +186,6 @@ code_scope(text, def) switch (def->df_sc) { case EXTERN: case GLOBAL: - case IMPLICIT: if (fund == FUNCTION) C_exp(text); else @@ -455,8 +454,7 @@ code_declaration(idf, expr, lvl, sc) ) def->df_alloc = ALLOC_SEEN; if (expr && def_sc == STATIC && sc == EXTERN) { - warning("%s redeclared extern", idf->id_text); - def->df_sc = EXTERN; + warning("%s has internal linkage", idf->id_text); } if (expr) { /* code only if initialized */ #ifndef PREPEND_SCOPES @@ -468,7 +466,7 @@ code_declaration(idf, expr, lvl, sc) } else if (lvl >= L_LOCAL) { /* local variable */ - /* STATIC, EXTERN, GLOBAL, IMPLICIT, AUTO or REGISTER */ + /* STATIC, EXTERN, GLOBAL, AUTO or REGISTER */ switch (def_sc) { case STATIC: if (fund == FUNCTION) { @@ -499,7 +497,6 @@ code_declaration(idf, expr, lvl, sc) error("cannot initialize extern in block" , idf->id_text); case GLOBAL: - case IMPLICIT: /* we are sure there is no expression */ break; case AUTO: diff --git a/lang/cem/cemcom.ansi/declar.g b/lang/cem/cemcom.ansi/declar.g index ed4b8e856..fd398b0be 100644 --- a/lang/cem/cemcom.ansi/declar.g +++ b/lang/cem/cemcom.ansi/declar.g @@ -234,7 +234,7 @@ initializer(struct idf *idf; int sc;) idf->id_def->df_type->tp_fund = ERRONEOUS; } if (level == L_FORMAL2) - warning("illegal initialization of formal parameter (ignored)"); + error("illegal initialization of formal parameter"); } '=' { diff --git a/lang/cem/cemcom.ansi/declarator.c b/lang/cem/cemcom.ansi/declarator.c index bbb19506d..549615f42 100644 --- a/lang/cem/cemcom.ansi/declarator.c +++ b/lang/cem/cemcom.ansi/declarator.c @@ -107,6 +107,11 @@ reject_params(dc) error("non_empty formal parameter pack"); free_formals(dc->dc_formal); dc->dc_formal = 0; + } else { + if (du && du->du_fund == FUNCTION + && !du->du_proto && !options['o']) { + warning("old-fashioned function declaration"); + } } while (du) { if (du->du_fund == FUNCTION) diff --git a/lang/cem/cemcom.ansi/decspecs.c b/lang/cem/cemcom.ansi/decspecs.c index 394fb690c..8a4555860 100644 --- a/lang/cem/cemcom.ansi/decspecs.c +++ b/lang/cem/cemcom.ansi/decspecs.c @@ -38,7 +38,7 @@ do_decspecs(ds) if ( level == L_GLOBAL && (ds->ds_sc == AUTO || ds->ds_sc == REGISTER) ) { - warning("no global %s variable allowed", + error("no global %s variable allowed", symbol2str(ds->ds_sc)); ds->ds_sc = GLOBAL; } diff --git a/lang/cem/cemcom.ansi/def.str b/lang/cem/cemcom.ansi/def.str index d85a0e915..222917c29 100644 --- a/lang/cem/cemcom.ansi/def.str +++ b/lang/cem/cemcom.ansi/def.str @@ -12,7 +12,7 @@ struct def { /* for ordinary tags */ int df_level; struct type *df_type; int df_sc; /* may be: - GLOBAL, STATIC, EXTERN, IMPLICIT, + GLOBAL, STATIC, EXTERN TYPEDEF, FORMAL, AUTO, ENUM, LABEL diff --git a/lang/cem/cemcom.ansi/domacro.c b/lang/cem/cemcom.ansi/domacro.c index 5a5f862b0..2cee0e299 100644 --- a/lang/cem/cemcom.ansi/domacro.c +++ b/lang/cem/cemcom.ansi/domacro.c @@ -530,7 +530,7 @@ getparams(buf, parbuf) */ for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--) { if (!strcmp(*pbuf2, *pbuf)) { - warning("formal parameter \"%s\" already used", + error("formal parameter \"%s\" already used", *pbuf); } } diff --git a/lang/cem/cemcom.ansi/eval.c b/lang/cem/cemcom.ansi/eval.c index e2d775269..2d5c41dc9 100644 --- a/lang/cem/cemcom.ansi/eval.c +++ b/lang/cem/cemcom.ansi/eval.c @@ -868,8 +868,7 @@ store_val(vl, tp) /* if (df->df_level == L_GLOBAL) { /* } ??? re-examine */ if (df->df_sc == GLOBAL || df->df_sc == EXTERN - || df->df_sc == STATIC - || df->df_sc == IMPLICIT) { + || df->df_sc == STATIC) { if (inword) C_ste_dnam(id->id_text, val); else @@ -980,8 +979,7 @@ load_val(expr, rlval) /* if (df->df_level == L_GLOBAL) { /* } ??? re-examine */ if ( df->df_sc == GLOBAL || df->df_sc == STATIC - || df->df_sc == EXTERN - || df->df_sc == IMPLICIT) { + || df->df_sc == EXTERN) { if (rvalue) { if (inword) C_loe_dnam(id->id_text, val); diff --git a/lang/cem/cemcom.ansi/expr.c b/lang/cem/cemcom.ansi/expr.c index e3b7b70b7..7d1787806 100644 --- a/lang/cem/cemcom.ansi/expr.c +++ b/lang/cem/cemcom.ansi/expr.c @@ -140,11 +140,11 @@ idf2expr(expr) if (def == 0) { if (AHEAD == '(') { - /* function call, declare name IMPLICITly (3.3.2.2) */ + /* function call, declare name implicitly (3.3.2.2) */ if (!options['o']) warning("implicit declaration of function %s" , idf->id_text); - add_def(idf, IMPLICIT, funint_type, level); + add_def(idf, EXTERN, funint_type, level); } else { if (!is_anon_idf(idf)) error("%s undefined", idf->id_text); diff --git a/lang/cem/cemcom.ansi/idf.c b/lang/cem/cemcom.ansi/idf.c index 74862105f..900915c62 100644 --- a/lang/cem/cemcom.ansi/idf.c +++ b/lang/cem/cemcom.ansi/idf.c @@ -34,6 +34,7 @@ int idfsize = IDFSIZE; extern char options[]; extern arith NewLocal(); +extern char *symbol2str(); char sp_occurred[SP_TOTAL+1]; /* indicate occurrence of special id */ @@ -204,7 +205,6 @@ declare_idf(ds, dc, lvl) /* the type is not yet known, but it has to be: */ - extern char *symbol2str(); if (type->tp_fund != VOID) { if (level != L_GLOBAL) error("unknown %s-type", @@ -250,10 +250,10 @@ declare_idf(ds, dc, lvl) if (lvl != L_GLOBAL) { /* 3.5.1 */ if (sc == 0) sc = GLOBAL; - else if (sc != EXTERN && sc != IMPLICIT) { + else if (sc != EXTERN) { error("illegal storage class %s for function with block-scope" , symbol2str(sc)); - ds->ds_sc = sc = GLOBAL; + ds->ds_sc = sc = EXTERN; } } else if (sc == 0) @@ -265,10 +265,6 @@ declare_idf(ds, dc, lvl) : lvl == L_FORMAL1 || lvl == L_FORMAL2 ? FORMAL : AUTO; - /* is it a universal typedef? */ - if (def && def->df_level == L_UNIVERSAL) - warning("redeclaring reserved word %s", idf->id_text); - #ifdef LINT if ( def && def->df_level < lvl && !( lvl == L_FORMAL2 @@ -326,21 +322,6 @@ declare_idf(ds, dc, lvl) def->df_file = idf->id_file; def->df_line = idf->id_line; } -#if 0 /* be more strict in scope (at least for now) */ - else - if ( lvl >= L_LOCAL && - (type->tp_fund == FUNCTION || sc == EXTERN) - ) { - /* extern declaration inside function is treated the - same way as global extern declaration - */ - if (sc == STATIC && type->tp_fund == FUNCTION) - if (!is_anon_idf(idf)) - warning("non-global static function %s", - idf->id_text); - declare_idf(ds, dc, L_GLOBAL); - } -#endif else { /* fill in the def block */ register struct def *newdef = new_def(); @@ -431,6 +412,9 @@ global_redecl(idf, new_sc, tp) if (def->df_type->tp_size < 0) { /* old decl has [] */ def->df_type = tp; } + } if (tp->tp_fund == FUNCTION && new_sc == GLOBAL) { + /* see 3.1.2.2 */ + new_sc = EXTERN; } /* Now we may be able to update the storage class. @@ -442,21 +426,18 @@ global_redecl(idf, new_sc, tp) level, without either "extern" or "static". STATIC: we have seen the word "static" - IMPLICIT: function declaration inferred from - call */ - if (new_sc == IMPLICIT) - return; /* no new information */ switch (def->df_sc) { /* the old storage class */ case EXTERN: switch (new_sc) { /* the new storage class */ - case EXTERN: - case GLOBAL: - break; case STATIC: - warning("redeclaration of %s to static ignored" - , idf->id_text); + warning("%s redeclared static", idf->id_text); + /* fallthrough */ + case GLOBAL: + def->df_sc = new_sc; + /* fallthrough */ + case EXTERN: break; default: crash("bad storage class"); @@ -465,14 +446,12 @@ global_redecl(idf, new_sc, tp) break; case GLOBAL: switch (new_sc) { /* the new storage class */ - case EXTERN: - def->df_sc = EXTERN; - break; + case STATIC: /* linkage disagreement */ + warning("%s redeclared static", idf->id_text); + def->df_sc = new_sc; + /* fallthrough */ case GLOBAL: - break; - case STATIC: - warning("redeclaration of %s to static ignored" - , idf->id_text); + case EXTERN: break; default: crash("bad storage class"); @@ -481,27 +460,11 @@ global_redecl(idf, new_sc, tp) break; case STATIC: switch (new_sc) { /* the new storage class */ - case GLOBAL: - warning("%s redeclared extern", idf->id_text); - def->df_sc = new_sc; - break; - case EXTERN: /* complain at definition */ - break; - case STATIC: - break; - default: - crash("bad storage class"); - /*NOTREACHED*/ - } - break; - case IMPLICIT: - switch (new_sc) { /* the new storage class */ + case GLOBAL: /* linkage disagreement */ case EXTERN: - case GLOBAL: - def->df_sc = new_sc; - break; + warning("%s is already declared static", idf->id_text); + /* fallthrough */ case STATIC: - def->df_sc = new_sc; break; default: crash("bad storage class"); @@ -559,8 +522,8 @@ init_idf(idf) if (def->df_initialized) error("multiple initialization of %s", idf->id_text); if (def->df_sc == TYPEDEF) { - warning("typedef cannot be initialized"); - def->df_sc = EXTERN; /* ??? *//* What else ? */ + error("typedef cannot be initialized"); + return; } def->df_initialized = 1; } diff --git a/lang/cem/cemcom.ansi/stack.c b/lang/cem/cemcom.ansi/stack.c index 879bd5b25..ba7716c18 100644 --- a/lang/cem/cemcom.ansi/stack.c +++ b/lang/cem/cemcom.ansi/stack.c @@ -217,13 +217,6 @@ unstack_world() def->df_used ? "used" : "not used"); } #endif DEBUG - /* - /_* find final storage class *_/ - if (def->df_sc == GLOBAL || def->df_sc == IMPLICIT) - /_* even now we still don't know *_/ - def->df_sc = EXTERN; - */ - if (def->df_sc == STATIC && def->df_type->tp_fund == FUNCTION && !def->df_initialized) { diff --git a/lang/cem/cemcom.ansi/tokenname.c b/lang/cem/cemcom.ansi/tokenname.c index fe97b4044..84cf2aa90 100644 --- a/lang/cem/cemcom.ansi/tokenname.c +++ b/lang/cem/cemcom.ansi/tokenname.c @@ -111,7 +111,6 @@ struct tokenname tkfunny[] = { /* internal keywords */ {FIELD, "field"}, {GLOBAL, "global"}, - {IMPLICIT, "implicit"}, {FORMAL, "formal"}, {LABEL, "label"}, {ERRONEOUS, "erroneous"},