bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lint warnings from `bison -y' generated files


From: Paul Eggert
Subject: Re: lint warnings from `bison -y' generated files
Date: Thu, 06 Oct 2005 00:22:49 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Akim Demaille <address@hidden> writes:

> You see me surprised!  You and I are militants of killing the
> warnings, so I do understand Nicolas' point, in particular in
> generated code.  This is somewhat inconsistent with your arguments
> pro-alloca.

OK, you talked me into it.  I added /*CONSTCMD*/ everywhere
I could find, as shown in the patch below.

> How about defining
> YY_ATTRIBUTE_UNUSED and see adjust its definition depending on the
> tool (I hate to say that...).  This is also better documentation.

OK, I defined YYUSE to do this.  It's not the same as
attribute((unused)) because it's not an attribute, but it should do
the trick.


Nicolas Joly <address@hidden> writes:

> It seems that you missed some. At least the one i'm facing in
> yydestruct() definition (data/c.m4:389) :

OK, the patch below catches that one too.

Here's what I installed.  Does this fix all your lint warnings?


2005-10-05  Paul Eggert  <address@hidden>

        * data/c.m4 (yydestruct, yysymprint):
        Use YYUSE instead of casting to void.
        * data/glr.c (YYUSE): New macro.
        (yyuserMerge, yyreportAmbiguity, yyreportSyntaxError):
        Use it instead of rolling our own.
        (YYLLOC_DEFAULT, YYCHK, YYDPRINTF, YY_SYMBOL_PRINT, YY_REDUCE_PRINT):
        (YYCHK1):
        Use /*CONSTCOND*/ to suppress lint warnings.
        * data/lalr1.cc (YYLLOC_DEFAULT, YY_SYMBOL_PRINT, YY_REDUCE_PRINT):
        (YY_STACK_PRINT): Use 'false' not '0'.
        (YYUSE): New macro.
        (yysymprint_, yydestruct_): Use it instead of rolling our own.
        * data/yacc.c (YYUSE): New macro.
        (YYCOPY, YYSTACK_RELOCATE, YYBACKUP, YYLLOC_DEFAULT):
        (YYDPRINTF, YY_SYMBOL_PRINT, YY_STACK_PRINT, YY_REDUCE_PRINT):
        (yyerrorlab): Use /*CONSTCOND*/ to suppress lint warnings.

Index: data/c.m4
===================================================================
RCS file: /cvsroot/bison/bison/data/c.m4,v
retrieving revision 1.35
diff -p -u -r1.35 c.m4
--- data/c.m4   5 Oct 2005 06:39:07 -0000       1.35
+++ data/c.m4   6 Oct 2005 07:15:59 -0000
@@ -385,9 +385,8 @@ m4_define_default([b4_yydestruct_generat
     [[YYSTYPE *yyvaluep],    [yyvaluep]]b4_location_if([,
     [[YYLTYPE *yylocationp], [yylocationp]]]))[
 {
-  /* Pacify ``unused variable'' warnings.  */
-  (void) yyvaluep;
-]b4_location_if([  (void) yylocationp;
+  YYUSE (yyvaluep);
+]b4_location_if([  YYUSE (yylocationp);
 ])[
   if (!yymsg)
     yymsg = "Deleting";
@@ -420,9 +419,8 @@ m4_define_default([b4_yysymprint_generat
     [[YYSTYPE *yyvaluep],    [yyvaluep]]b4_location_if([,
     [[YYLTYPE *yylocationp], [yylocationp]]]))
 {
-  /* Pacify ``unused variable'' warnings.  */
-  (void) yyvaluep;
-b4_location_if([  (void) yylocationp;
+  YYUSE (yyvaluep);
+b4_location_if([  YYUSE (yylocationp);
 ])dnl
 [
   if (yytype < YYNTOKENS)
Index: data/glr.c
===================================================================
RCS file: /cvsroot/bison/bison/data/glr.c,v
retrieving revision 1.128
diff -p -u -r1.128 glr.c
--- data/glr.c  5 Oct 2005 06:39:07 -0000       1.128
+++ data/glr.c  6 Oct 2005 07:15:59 -0000
@@ -234,6 +234,9 @@ b4_syncline(address@hidden@], address@hidden@])
 # endif
 #endif
 
+/* Suppress unused-variable warnings by "using" E.  */
+#define YYUSE(e) do {;} while (/*CONSTCOND*/ yyfalse && (e))
+
 #ifndef YYFREE
 # define YYFREE free
 #endif
@@ -470,7 +473,7 @@ static const ]b4_int_type_for([b4_stos])
          (Current).first_column = (Current).last_column =              \
            YYRHSLOC (Rhs, 0).last_column;                              \
        }                                                               \
-    while (0)
+    while (/*CONSTCOND*/ 0)
 
 /* YY_LOCATION_PRINT -- Print the location on the stream.
    This macro was not mandated originally: define only if we know
@@ -515,7 +518,7 @@ typedef enum { yyok, yyaccept, yyabort, 
 
 #define YYCHK(YYE)                                                          \
    do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; }      \
-   while (0)
+   while (/*CONSTCOND*/ 0)
 
 #if YYDEBUG
 
@@ -527,7 +530,7 @@ typedef enum { yyok, yyaccept, yyabort, 
 do {                                           \
   if (yydebug)                                 \
     YYFPRINTF Args;                            \
-} while (0)
+} while (/*CONSTCOND*/ 0)
 
 ]b4_yysymprint_generate([b4_c_ansi_function_def])[
 
@@ -540,7 +543,7 @@ do {                                                        
        \
                   Type, Value]b4_location_if([, Location])[);  \
       YYFPRINTF (stderr, "\n");                                        \
     }                                                          \
-} while (0)
+} while (/*CONSTCOND*/ 0)
 
 /* Nonzero means print parse trace.  It is left uninitialized so that
    multiple parsers can coexist.  */
@@ -877,9 +880,8 @@ b4_syncline(address@hidden@], address@hidden@])
 static void
 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
 {
-  /* Suppress unused-variable warnings.  */
-  yy0 = yy0;
-  yy1 = yy1;
+  YYUSE (yy0);
+  YYUSE (yy1);
 
   switch (yyn)
     {
@@ -1306,7 +1308,7 @@ yydoAction (yyGLRStack* yystack, size_t 
 do {                                   \
   if (yydebug)                         \
     yy_reduce_print (K, Rule);         \
-} while (0)
+} while (/*CONSTCOND*/ 0)
 
 /*----------------------------------------------------------.
 | Report that the RULE is going to be reduced on stack #K.  |
@@ -1621,9 +1623,8 @@ static void
 yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
                   yyGLRStack* yystack]b4_pure_formals[)
 {
-  /* Suppress unused-variable warnings.  */
-  yyx0 = yyx0;
-  yyx1 = yyx1;
+  YYUSE (yyx0);
+  YYUSE (yyx1);
 
 #if YYDEBUG
   YYFPRINTF (stderr, "Ambiguity detected.\n");
@@ -1836,9 +1837,8 @@ static void
 yyreportSyntaxError (yyGLRStack* yystack,
                     YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[)
 {
-  /* Suppress unused-variable warnings.  */
-  yylvalp = yylvalp;
-  yyllocp = yyllocp;
+  YYUSE (yylvalp);
+  YYUSE (yyllocp);
 
   if (yystack->yyerrState == 0)
     {
@@ -2046,7 +2046,7 @@ yyrecoverSyntaxError (yyGLRStack* yystac
     default:                                                                \
       goto yybuglab;                                                        \
     }                                                                       \
-  } while (0)
+  } while (/*CONSTCOND*/ 0)
 
 
 /*----------.
Index: data/lalr1.cc
===================================================================
RCS file: /cvsroot/bison/bison/data/lalr1.cc,v
retrieving revision 1.107
diff -p -u -r1.107 lalr1.cc
--- data/lalr1.cc       5 Oct 2005 06:05:22 -0000       1.107
+++ data/lalr1.cc       6 Oct 2005 07:15:59 -0000
@@ -88,7 +88,7 @@ do {                                                  \
     {                                                  \
       (Current).begin = (Current).end = (Rhs)[0].end;  \
     }                                                  \
-} while (0)
+} while (false)
 #endif
 
 namespace yy
@@ -319,6 +319,9 @@ b4_syncline(address@hidden@], address@hidden@])[
 # endif
 #endif
 
+/* Suppress unused-variable warnings by "using" E.  */
+#define YYUSE(e) do {;} while (false && (e))
+
 /* A pseudo ostream that takes yydebug_ into account. */
 # define YYCDEBUG                                                      \
   for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false)       
\
@@ -335,19 +338,19 @@ do {                                                      
\
       yysymprint_ ((Type), (Value), (Location));       \
       *yycdebug_ << std::endl;                         \
     }                                                  \
-} while (0)
+} while (false)
 
 # define YY_REDUCE_PRINT(Rule)         \
 do {                                   \
   if (yydebug_)                                \
     yyreduce_print_ (Rule);            \
-} while (0)
+} while (false)
 
 # define YY_STACK_PRINT()              \
 do {                                   \
   if (yydebug_)                                \
     yystack_print_ ();                 \
-} while (0)
+} while (false)
 
 #else /* !YYDEBUG */
 
@@ -414,9 +417,9 @@ yy::]b4_parser_class_name[::yysymprint_ 
   /* Backward compatibility, but should be removed eventually. */
   std::ostream& cdebug_ = *yycdebug_;
 
-  /* Suppress unused-variable warnings.  */
-  if (false)
-    yysymprint_ (yytype + !&cdebug_, yyvaluep, yylocationp);
+  YYUSE (!&cdebug_);
+  YYUSE (yylocationp);
+  YYUSE (yyvaluep);
 
   *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
             << ' ' << yytname_[yytype] << " ("
@@ -435,9 +438,9 @@ void
 yy::]b4_parser_class_name[::yydestruct_ (const char* yymsg,
                          int yytype, semantic_type* yyvaluep, location_type* 
yylocationp)
 {
-  /* Suppress unused-variable warnings.  */
-  if (false)
-    yydestruct_ (yymsg, yytype, yyvaluep, yylocationp);
+  YYUSE (yylocationp);
+  YYUSE (yymsg);
+  YYUSE (yyvaluep);
 
   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
 
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.112
diff -p -u -r1.112 yacc.c
--- data/yacc.c 5 Oct 2005 06:39:07 -0000       1.112
+++ data/yacc.c 6 Oct 2005 07:15:59 -0000
@@ -246,6 +246,9 @@ b4_syncline(address@hidden@], address@hidden@])[
 # endif
 #endif
 
+/* Suppress unused-variable warnings by "using" E.  */
+#define YYUSE(e) do {;} while (/*CONSTCOND*/ 0 && (e))
+
 #if ! defined (yyoverflow) || YYERROR_VERBOSE
 
 /* The parser invokes alloca or malloc; define the necessary symbols.  */
@@ -355,7 +358,7 @@ union yyalloc
          for (yyi = 0; yyi < (Count); yyi++)   \
            (To)[yyi] = (From)[yyi];            \
        }                                       \
-      while (0)
+      while (/*CONSTCOND*/ 0)
 #  endif
 # endif
 
@@ -373,7 +376,7 @@ union yyalloc
        yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
        yyptr += yynewbytes / sizeof (*yyptr);                          \
       }                                                                        
\
-    while (0)
+    while (/*CONSTCOND*/ 0)
 
 #endif
 
@@ -544,7 +547,7 @@ do                                                          
\
       yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")); \
       YYERROR;                                                 \
     }                                                          \
-while (0)
+while (/*CONSTCOND*/ 0)
 
 
 #define YYTERROR       1
@@ -573,7 +576,7 @@ while (0)
          (Current).first_column = (Current).last_column =              \
            YYRHSLOC (Rhs, 0).last_column;                              \
        }                                                               \
-    while (0)
+    while (/*CONSTCOND*/ 0)
 #endif
 
 
@@ -613,7 +616,7 @@ while (0)
 do {                                           \
   if (yydebug)                                 \
     YYFPRINTF Args;                            \
-} while (0)
+} while (/*CONSTCOND*/ 0)
 
 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)         \
 do {                                                           \
@@ -624,7 +627,7 @@ do {                                                        
        \
                   Type, Value]b4_location_if([, Location])[);  \
       YYFPRINTF (stderr, "\n");                                        \
     }                                                          \
-} while (0)
+} while (/*CONSTCOND*/ 0)
 
 /*------------------------------------------------------------------.
 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
@@ -645,7 +648,7 @@ do {                                                        
        \
 do {                                                           \
   if (yydebug)                                                 \
     yy_stack_print ((Bottom), (Top));                          \
-} while (0)
+} while (/*CONSTCOND*/ 0)
 
 
 /*------------------------------------------------.
@@ -669,7 +672,7 @@ do {                                                        
        \
 do {                                   \
   if (yydebug)                         \
     yy_reduce_print (Rule);            \
-} while (0)
+} while (/*CONSTCOND*/ 0)
 
 /* Nonzero means print parse trace.  It is left uninitialized so that
    multiple parsers can coexist.  */
@@ -1351,7 +1354,7 @@ yyerrorlab:
   /* Pacify compilers like GCC when the user code never invokes
      YYERROR and the label yyerrorlab therefore never appears in user
      code.  */
-  if (0)
+  if (/*CONSTCOND*/ 0)
      goto yyerrorlab;
 
 ]b4_location_if([[  yyerror_range[0] = yylsp[1-yylen];




reply via email to

[Prev in Thread] Current Thread [Next in Thread]