From: epetrich Date: Tue, 12 Aug 2003 08:44:47 +0000 (+0000) Subject: Generate warnings for useless declarations like "char data;" X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=1529c05be1991fcd88bfea5c971971c7838efe74;p=fw%2Fsdcc 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 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2822 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 7f65ec78..b1fb8c30 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2003-08-12 Erik Petrich + + 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 * src/SDCCval.c (valMult): fixex overflow detection of negativ int diff --git a/src/SDCC.y b/src/SDCC.y index 4d4d5fa2..5847cbe7 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -57,6 +57,7 @@ STACK_DCL(swStk ,ast *,MAX_NEST_LEVEL) STACK_DCL(blockNum,int,MAX_NEST_LEVEL*3) value *cenum = NULL ; /* current enumeration type chain*/ +bool uselessDecl = TRUE; %} %expect 6 @@ -459,7 +460,13 @@ constant_expr ; 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 */ @@ -472,6 +479,7 @@ declaration addDecl (sym,0,lnk) ; } + uselessDecl = TRUE; $$ = sym1 ; } ; @@ -629,9 +637,13 @@ type_specifier2 SPEC_BSTR($$) = 0; } - | struct_or_union_specifier + | struct_or_union_specifier { + uselessDecl = FALSE; + $$ = $1 ; + } | enum_specifier { cenum = NULL ; + uselessDecl = FALSE; $$ = $1 ; } | TYPE_NAME diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index 7e46d97b..3fdc279f 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -387,6 +387,8 @@ struct "'%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)" }, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index 70dade38..bb8510e4 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -181,6 +181,7 @@ SDCCERR - SDCC Standard error handler #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.