[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2] Avoid warnings from gcc -Wunused y.tab.c
From: |
Jonathan Nieder |
Subject: |
[PATCH v2] Avoid warnings from gcc -Wunused y.tab.c |
Date: |
Tue, 15 Dec 2009 21:47:01 -0600 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
Hi Joel,
Here is an updated patch incorporating all your suggestions except for
the last one.
Joel E. Denny wrote:
> How does the b4_locations_if part of this change help? If it isn't really
> necessary, then let's drop it. As far as I can tell, the addition of
> `defined YYLTYPE_IS_TRIVIAL &&' is sufficient.
I tried to make it a little clearer what the conditional is for in
this version. If you still think the conditional should be dropped,
let me know and I’ll send a version without it.
Ciao,
-- %< --
>From 81895390b3b97540e4ade42031449700d10d62bd Mon Sep 17 00:00:00 2001
From: Jonathan Nieder <address@hidden>
Date: Sat, 12 Dec 2009 15:43:18 -0600
Subject: [PATCH] Avoid warnings from gcc -Wunused y.tab.c
Building bison-produced parsers can result in a few warnings:
y.tab.c:383:6: warning: "YYENABLE_NLS" is not defined
y.tab.c:1271:6: warning: "YYLTYPE_IS_TRIVIAL" is not defined
These warnings are not revealing any actual problem (it is
perfectly reasonable to use #if FOO even if FOO is not defined).
Suppress them by checking if preprocessor symbols are defined
before using their values.
While at it, do not use the YYLTYPE_IS_TRIVIAL symbol in the
generated parser source if location tracking is not enabled.
(Most uses were protected by b4_locations_if already.)
---
ChangeLog | 15 +++++++++++++++
data/glr.c | 4 ++--
data/lalr1.cc | 2 +-
data/yacc.c | 14 ++++++++++----
4 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2c5d33e..1f7fd6b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2009-12-15 Jonathan Nieder <address@hidden>
+
+ Check defined FOO && FOO instead of FOO when testing
+ user-defined preprocessor symbols.
+ This avoids warnings from gcc -Wunused y.tab.c.
+ * data/glr.c: Test if YYENABLE_NLS is defined before using it.
+ * data/lalr1.cc: Likewise.
+ * data/yacc.c: Likewise.
+ * data/glr.c: Test if YYLTYPE_IS_TRIVIAL is defined before
+ using it.
+ * data/yacc.c: If location tracking is enabled, test if
+ YYLTYPE_IS_TRIVIAL is defined before using it. Otherwise, do
+ not use it: define YY_LOCATION_PRINT as a no-op unconditionally
+ and add a comment explaining why.
+
2009-12-15 Joel E. Denny <address@hidden>
autoconf: update to latest for fix of M4 detection.
diff --git a/data/glr.c b/data/glr.c
index 6f1f7ee..e73b251 100644
--- a/data/glr.c
+++ b/data/glr.c
@@ -256,7 +256,7 @@ b4_percent_code_get[]dnl
#include <string.h>
#ifndef YY_
-# if YYENABLE_NLS
+# if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
# define YY_(msgid) dgettext ("bison-runtime", msgid)
@@ -2264,7 +2264,7 @@ yyrecoverSyntaxError (yyGLRStack*
yystackp]b4_user_formals[)
yychar = YYEMPTY;
yylval = yyval_default;
]b4_locations_if([
-#if YYLTYPE_IS_TRIVIAL
+#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[;
yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[;
#endif
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 1a2777e..9e0d522 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -398,7 +398,7 @@ m4_if(b4_prefix, [yy], [],
b4_percent_code_get[]dnl
[#ifndef YY_
-# if YYENABLE_NLS
+# if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
# define YY_(msgid) dgettext ("bison-runtime", msgid)
diff --git a/data/yacc.c b/data/yacc.c
index ea2ae14..04c6a90 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -374,7 +374,7 @@ typedef short int yytype_int16;
#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
#ifndef YY_
-# if YYENABLE_NLS
+# if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
# define YY_(msgid) dgettext ("bison-runtime", msgid)
@@ -662,13 +662,13 @@ while (YYID (0))
while (YYID (0))
#endif
-
+]b4_locations_if([[
/* YY_LOCATION_PRINT -- Print the location on the stream.
This macro was not mandated originally: define only if we know
we won't break user code: when these are the locations we know. */
#ifndef YY_LOCATION_PRINT
-# if YYLTYPE_IS_TRIVIAL
+# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
# define YY_LOCATION_PRINT(File, Loc) \
fprintf (File, "%d.%d-%d.%d", \
(Loc).first_line, (Loc).first_column, \
@@ -677,7 +677,13 @@ while (YYID (0))
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
# endif
#endif
+]], [[
+/* This macro is provided for backwards compatibility. */
+#ifndef YY_LOCATION_PRINT
+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+#endif
+]])[
/* YYLEX -- calling `yylex' with the right arguments. */
@@ -1192,7 +1198,7 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[
yyvsp = yyvs;]b4_locations_if([[
yylsp = yyls;
-#if YYLTYPE_IS_TRIVIAL
+#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
/* Initialize the default location before parsing starts. */
yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[;
yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[;
--
1.6.5.4
- [PATCH 2/2] Do not depend on YYLTYPE_IS_TRIVIAL unless locations are requested, (continued)
- [PATCH 2/2] Do not depend on YYLTYPE_IS_TRIVIAL unless locations are requested, Jonathan Nieder, 2009/12/12
- Re: several messages, Joel E. Denny, 2009/12/15
- Re: several messages, Jonathan Nieder, 2009/12/15
- Re: several messages, Joel E. Denny, 2009/12/15
- Re: several messages, Jonathan Nieder, 2009/12/15
- Re: several messages, Joel E. Denny, 2009/12/15
- Re: several messages, Jonathan Nieder, 2009/12/15
- Re: several messages, Joel E. Denny, 2009/12/15
- Re: several messages, Joel E. Denny, 2009/12/16
- Re: several messages, Joel E. Denny, 2009/12/16
- [PATCH v2] Avoid warnings from gcc -Wunused y.tab.c,
Jonathan Nieder <=
- Re: [PATCH v2] Avoid warnings from gcc -Wunused y.tab.c, Joel E. Denny, 2009/12/15