added warning about old-fashioned declarations

cleaned up error reporting
changed implicit declaration handling
This commit is contained in:
eck 1990-11-02 09:23:27 +00:00
parent 7de2babe56
commit d7c15759ee
12 changed files with 40 additions and 85 deletions

View file

@ -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 {

View file

@ -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:

View file

@ -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");
}
'='
{

View file

@ -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)

View file

@ -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;
}

View file

@ -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

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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;
}

View file

@ -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) {

View file

@ -111,7 +111,6 @@ struct tokenname tkfunny[] = { /* internal keywords */
{FIELD, "field"},
{GLOBAL, "global"},
{IMPLICIT, "implicit"},
{FORMAL, "formal"},
{LABEL, "label"},
{ERRONEOUS, "erroneous"},