lalr1.cc: don't generate useless constructors when variant is used

This generates less code, which is nicer to read, but also takes less
chances with compilers such as G++ 4.8 that are too strict and check
"dead code" (templated code that is not instantiated).

* data/c++.m4 (b4_symbol_type_declare, b4_symbol_type_define): When
variants are used, don't generate code meant for non variants.
This commit is contained in:
Akim Demaille
2018-09-09 10:06:57 +02:00
parent 171b6bacb9
commit 7194099027

View File

@@ -222,12 +222,12 @@ m4_define([b4_symbol_type_declare],
]b4_type_foreach([b4_basic_symbol_constructor_declare])], [[
/// Constructor for valueless symbols.
basic_symbol (typename Base::kind_type t]b4_locations_if([,
const location_type& l])[);]])[
const location_type& l])[);
/// Constructor for symbols with semantic value.
basic_symbol (typename Base::kind_type t,
const semantic_type& v]b4_locations_if([,
const location_type& l])[);
const location_type& l])[);]])[
/// Destroy the symbol.
~basic_symbol ();
@@ -317,18 +317,6 @@ m4_define([b4_public_types_define],
[other.value])])[
}
template <typename Base>
]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join(
[typename Base::kind_type t],
[const semantic_type& v],
b4_locations_if([const location_type& l]))[)
: Base (t)
, value (]b4_variant_if([], [v])[)]b4_locations_if([
, location (l)])[
{]b4_variant_if([[
(void) v;
]b4_symbol_variant([this->type_get ()], [value], [copy], [v])])[}
]b4_variant_if([[
// Implementation of basic_symbol constructor for each type.
]b4_type_foreach([b4_basic_symbol_constructor_define])], [[
@@ -340,7 +328,19 @@ m4_define([b4_public_types_define],
: Base (t)
, value ()]b4_locations_if([
, location (l)])[
{}]])[
{}
template <typename Base>
]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join(
[typename Base::kind_type t],
[const semantic_type& v],
b4_locations_if([const location_type& l]))[)
: Base (t)
, value (]b4_variant_if([], [v])[)]b4_locations_if([
, location (l)])[
{]b4_variant_if([[
(void) v;
]b4_symbol_variant([this->type_get ()], [value], [copy], [v])])[}]])[
template <typename Base>
]b4_parser_class_name[::basic_symbol<Base>::~basic_symbol ()