glr2.cc: fix warnings about uninitialized locations

With GCC10, the CI shows tons of warnings such as
(327. actions.at:374: testing Initial location: glr2.cc):

    input.cc: In member function 'YYRESULTTAG glr_stack::yyglrReduce(state_set_index, rule_num, bool)':
    input.cc:1357:11: error: '<anonymous>.glr_state::yyloc' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     1357 |     yyloc = other.yyloc;
          |     ~~~~~~^~~~~~~~~~~~~

This is because we don't have the constructors for locations.  But we
should have them!  That's only because of glr.cc that ctors were not
enabled by default.  In glr2.cc, they should.

That fixes all the warnings when Bison's locations are used.  However,
when user-defined locations without constructor are used, we still
have:

    550. calc.at:1409: testing Calculator glr2.cc %locations api.location.type={Span}  ...
    calc.cc: In member function 'YYRESULTTAG glr_stack::yyglrReduce(state_set_index, rule_num, bool)':
    calc.cc:1261:11: error: '<anonymous>.glr_state::yyloc' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     1261 |     yyloc = other.yyloc;
          |     ~~~~~~^~~~~~~~~~~~~

To address this case, we need glr_state to explicily initialize its
yyloc member.

* data/skeletons/glr2.cc: Use genuine objects, with ctors, for position
and location.
(glr_state): Explicitly initialize yyloc in the constructors.
This commit is contained in:
Akim Demaille
2020-12-25 10:47:12 +01:00
parent baea8cf9fa
commit 734ce73bf2

View File

@@ -40,21 +40,14 @@ m4_define([b4_tname_if],
# (b4_parse_param_orig). Note that b4_parse_param is overquoted
# (and c.m4 strips one level of quotes). This is a PITA, and
# explains why there are so many levels of quotes.
#
# The locations
#
# We use location.cc just like lalr1.cc, but because glr.c stores
# the locations in a union, the position and location classes
# must not have a constructor. Therefore, contrary to lalr1.cc, we
# must not define "b4_location_constructors". As a consequence the
# user must initialize the first positions (in particular the
# filename member).
# We require a pure interface.
m4_define([b4_pure_flag], [1])
m4_include(b4_skeletonsdir/[c++.m4])
b4_bison_locations_if([m4_include(b4_skeletonsdir/[location.cc])])
b4_bison_locations_if([
m4_define([b4_location_constructors])
m4_include(b4_skeletonsdir/[location.cc])])
m4_define([b4_parser_class],
[b4_percent_define_get([[api.parser.class]])])
@@ -777,7 +770,8 @@ public:
: yyresolved (false)
, yylrState (0)
, yyposn (0)
, yypred (0)]b4_parse_assert_if([[
, yypred (0)]b4_locations_if([[
, yyloc ()]])[]b4_parse_assert_if([[
, magic_ (MAGIC)]])[
{}
@@ -798,7 +792,8 @@ public:
, yylrState (lrState)
, yyposn (posn)
, yypred (0)
, yyfirstVal (0)]b4_parse_assert_if([[
, yyfirstVal (0)]b4_locations_if([[
, yyloc ()]])[]b4_parse_assert_if([[
, magic_ (MAGIC)]])[
{}