bug-bison
[Top][All Lists]
Advanced

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

[Bison 1.875] Parser won't compile with g++ 2.95.3


From: Russ Allbery
Subject: [Bison 1.875] Parser won't compile with g++ 2.95.3
Date: Fri, 31 Jan 2003 15:44:47 -0800
User-agent: Gnus/5.090008 (Oort Gnus v0.08) XEmacs/21.4 (Honest Recruiter, sparc-sun-solaris2.6)

If a parser uses yylloc, bison 1.875 generates code that looks like:

    /*----------------------------------------------------.
    | yyerrlab1 -- error raised explicitly by an action.  |
    `----------------------------------------------------*/
    yyerrlab1:
    
      /* Suppress GCC warning that yyerrlab1 is unused when no action
         invokes YYERROR.  */
    #if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__)
      __attribute__ ((__unused__))
    #endif
    
      yylerrsp = yylsp;
      *++yylerrsp = yyloc;
      goto yyerrlab2;

g++ 2.95.3 translates that into:

    __attribute__ ((__unused__)) yylerrsp = yylsp;

which it interprets as an implicit declaration of yylerrsp with type int,
causing predictable carnage on the rest of the compilation.  For whatever
reason, the attribute is not being associated with the label, and is
instead being associated with the following statement.

If yylloc is not used in the parser, this code is not inserted into the
generated parser and the only statement in this section is a goto, which
apparently lets g++ 2.95.3 disambiguate properly.

The following patch to yacc.c makes the problem go away:

--- bison-1.875/data/yacc.c.orig        2002-12-28 00:36:02.000001000 -0800
+++ bison-1.875/data/yacc.c     2003-01-31 15:20:48.000002000 -0800
@@ -1111,12 +1111,6 @@
 `----------------------------------------------------*/
 yyerrlab1:
 
-  /* Suppress GCC warning that yyerrlab1 is unused when no action
-     invokes YYERROR.  */
-#if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__)
-  __attribute__ ((__unused__))
-#endif
-
 ]b4_location_if([  yylerrsp = yylsp;
   *++yylerrsp = yyloc;])[
   goto yyerrlab2;

This is presumably not the best fix; the best fix would be to narrow the
range of GCC versions that can handle this construct.  I don't have a
sufficient number of GCC versions installed to narrow this down further.
Perhaps it's just g++ that's the problem and that warning suppression
shouldn't be generated if the compiler is g++.

The following sample file demonstrates the problem:

windlord:/tmp> cat parser.y
%{
int yylex(void);
void yyerror(char *msg);
%}
%%
top     :       "foo"   { @1; }
%%
windlord:/tmp> bison parser.y
windlord:/tmp> gcc -c -o parser.tab.o parser.tab.c
windlord:/tmp> g++ -c -o parser.tab.o parser.tab.c
parser.tab.c: In function `int yyparse()':
parser.tab.c:1101: ANSI C++ forbids declaration `yylerrsp' with no type
parser.tab.c:1101: conflicting types for `int yylerrsp'
parser.tab.c:748: previous declaration as `struct YYLTYPE * yylerrsp'
parser.tab.c:1101: initialization to `int' from `YYLTYPE *' lacks a cast
parser.tab.c:1102: invalid type argument of `unary *'
parser.tab.c:1144: invalid operands `int' and `YYLTYPE *' to binary `operator -'
parser.tab.c:1144: invalid operands `int' and `YYLTYPE *' to binary `operator -'

windlord:/tmp> bison --version
bison (GNU Bison) 1.875
Written by Robert Corbett and Richard Stallman.

Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

windlord:/tmp> g++ -v
Reading specs from /usr/pubsw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/specs
gcc version 2.95.3 20010315 (release)

-- 
Russ Allbery (address@hidden)             <http://www.eyrie.org/~eagle/>




reply via email to

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