[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Duplicate definition of YYUSE macro
From: |
Frank Heckenbach |
Subject: |
Duplicate definition of YYUSE macro |
Date: |
Sun, 30 Jun 2019 02:26:06 +0200 |
Hi,
when I added the "-Wunused-macros" warning to my compiler calls in
order to find macros not used anymore in my code (it did find some),
my Bison parsers also produced a few of these warnings. I understand
that, so to avoid having to use different compiler options for
Bison-generated files, I added:
#pragma GCC diagnostic ignored "-Wunused-macros"
This suppressed most of the warnings, but to my surprise, one of
them remained and, ironically, it's the "YYUSE" macro that
ostensibly is not used. To reproduce:
% cat unused.yy
%skeleton "lalr1.cc"
%{
int yylex (void *);
#pragma GCC diagnostic ignored "-Wunused-macros"
%}
%%
a: %empty;
% bison unused.yy && g++ -c -Wunused-macros unused.tab.cc
unused.tab.cc:114: warning: macro "YYUSE" is not used [-Wunused-macros]
So I looked in the generated file and found this:
// ...
/* Suppress unused-variable warnings by "using" E. */
#if ! defined lint || defined __GNUC__
# define YYUSE(E) ((void) (E))
#else
# define YYUSE(E) /* empty */
#endif
// ...
// Suppress unused-variable warnings by "using" E.
#define YYUSE(E) ((void) (E))
// ...
YYUSE (yysym.type_get ());
So YYUSE is in fact used, but after being defined twice.
AFAIK, that's not wrong, and even if one could argue that the first
definition is unused, the pragma should suppress it, so this seems
to be a GCC bug which I just reported:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91037
However, as far as Bison is concerned, I wonder if it's actually
intended that the macro is defined twice, and in fact both
definitions might differ, depending on the conditionals.
AFAICS, the two definitions come from c.m4 and lalr1.cc,
respectively. Since the latter uses the former (via c++.m4), it
seems the second one can safely be removed. I just tested it with
split-header and single-file parsers and found no difference, except
for the above warning disappearing.
Regards,
Frank
- Duplicate definition of YYUSE macro,
Frank Heckenbach <=