+2003-08-12 Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+ Generate warnings for useless declarations like "char data;"
+ that don't do what new users expect.
+
+ * src/SDCC.y
+ * support/Util/SDCCerr.h
+ * support/Util/SDCCerr.c
+
2003-08-09 Bernhard Held <bernhard@bernhardheld.de>
* src/SDCCval.c (valMult): fixex overflow detection of negativ int
STACK_DCL(blockNum,int,MAX_NEST_LEVEL*3)
value *cenum = NULL ; /* current enumeration type chain*/
+bool uselessDecl = TRUE;
%}
%expect 6
;
declaration
- : declaration_specifiers ';' { $$ = NULL ; }
+ : declaration_specifiers ';'
+ {
+ if (uselessDecl)
+ werror(W_USELESS_DECL);
+ uselessDecl = TRUE;
+ $$ = NULL ;
+ }
| declaration_specifiers init_declarator_list ';'
{
/* add the specifier list to the id */
addDecl (sym,0,lnk) ;
}
+ uselessDecl = TRUE;
$$ = sym1 ;
}
;
SPEC_BSTR($$) = 0;
}
- | struct_or_union_specifier
+ | struct_or_union_specifier {
+ uselessDecl = FALSE;
+ $$ = $1 ;
+ }
| enum_specifier {
cenum = NULL ;
+ uselessDecl = FALSE;
$$ = $1 ;
}
| TYPE_NAME
"'%s' internal stack %s" },
{ W_INT_OVL, ERROR_LEVEL_WARNING,
"integer overflow in expression" },
+{ W_USELESS_DECL, ERROR_LEVEL_WARNING,
+ "useless declaration (possible use of keyword as variable name)" },
};
/*
#define E_DUPLICATE_MEMBER 163
#define E_STACK_VIOLATION 164 /* internal stack violation */
#define W_INT_OVL 165 /* integer overflow in expression */
+#define W_USELESS_DECL 166 /* useless declaration */
/** Describes the maximum error level that will be logged. Any level
* includes all of the levels listed after it.