]> git.saurik.com Git - bison.git/commitdiff
c++: please G++ 4.8 with -O3: array bounds
authorAkim Demaille <akim@lrde.epita.fr>
Tue, 29 Jan 2013 07:52:57 +0000 (08:52 +0100)
committerAkim Demaille <akim@lrde.epita.fr>
Tue, 29 Jan 2013 08:04:08 +0000 (09:04 +0100)
* data/c++.m4, data/lalr1.cc (by_state, by_type): Do not use -1 to
denote the absence of value, as GCC then fears that this -1 might
be used to dereference arrays (such as yytname).
Use 0, which corresponds to $accept, which is valueless (the needed
property: the symbol destructor must not try to reclaim the memory
associated with the symbol).

data/c++.m4
data/lalr1.cc

index e91b90d79e8397b3bbb4cde221ff61a47ede88d2..87bc5e0dcf184ab5fc3bea00154c8ac8bbe36bab 100644 (file)
@@ -231,6 +231,8 @@ m4_define([b4_public_types_declare],
       /// The token.
       token_type token () const;
 
       /// The token.
       token_type token () const;
 
+      enum { empty = 0 };
+
       /// The symbol type.
       ///
       /// -1 when this symbol is empty.
       /// The symbol type.
       ///
       /// -1 when this symbol is empty.
@@ -328,7 +330,7 @@ m4_define([b4_public_types_define],
   // by_type.
   inline
   ]b4_parser_class_name[::by_type::by_type ()
   // by_type.
   inline
   ]b4_parser_class_name[::by_type::by_type ()
-     : type (-1)
+     : type (empty)
   {}
 
   inline
   {}
 
   inline
@@ -346,7 +348,7 @@ m4_define([b4_public_types_define],
   ]b4_parser_class_name[::by_type::move (by_type& that)
   {
     type = that.type;
   ]b4_parser_class_name[::by_type::move (by_type& that)
   {
     type = that.type;
-    that.type = -1;
+    that.type = empty;
   }
 
   inline
   }
 
   inline
index 473dd29bd571f3c4ea300b004cdfef030e68d16d..eb4883559a414287500ee6bfb3ac01f5b9c524e3 100644 (file)
@@ -284,9 +284,11 @@ b4_location_define])])[
       void move (by_state& that);
 
       /// The (internal) type number (corresponding to \a state).
       void move (by_state& that);
 
       /// The (internal) type number (corresponding to \a state).
-      /// -1 when empty.
+      /// "empty" when empty.
       symbol_number_type type_get () const;
 
       symbol_number_type type_get () const;
 
+      enum { empty = 0 };
+
       /// The state.
       state_type state;
     };
       /// The state.
       state_type state;
     };
@@ -523,7 +525,7 @@ m4_if(b4_prefix, [yy], [],
   // by_state.
   inline
   ]b4_parser_class_name[::by_state::by_state ()
   // by_state.
   inline
   ]b4_parser_class_name[::by_state::by_state ()
-    : state (-1)
+    : state (empty)
   {}
 
   inline
   {}
 
   inline
@@ -536,7 +538,7 @@ m4_if(b4_prefix, [yy], [],
   ]b4_parser_class_name[::by_state::move (by_state& that)
   {
     state = that.state;
   ]b4_parser_class_name[::by_state::move (by_state& that)
   {
     state = that.state;
-    that.state = -1;
+    that.state = empty;
   }
 
   inline
   }
 
   inline
@@ -548,7 +550,7 @@ m4_if(b4_prefix, [yy], [],
   ]b4_parser_class_name[::symbol_number_type
   ]b4_parser_class_name[::by_state::type_get () const
   {
   ]b4_parser_class_name[::symbol_number_type
   ]b4_parser_class_name[::by_state::type_get () const
   {
-    return state == -1 ? -1 : yystos_[state];
+    return state == empty ? 0 : yystos_[state];
   }
 
   inline
   }
 
   inline
@@ -564,7 +566,7 @@ m4_if(b4_prefix, [yy], [],
                                       [value], [move], [that.value])],
                    [[value = that.value;]])[
     // that is emptied.
                                       [value], [move], [that.value])],
                    [[value = that.value;]])[
     // that is emptied.
-    that.type = -1;
+    that.type = empty;
   }
 
   inline
   }
 
   inline