From 719409902792540be3641e637dc248797e1ee4fd Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 9 Sep 2018 10:06:57 +0200 Subject: [PATCH] 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. --- data/c++.m4 | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/data/c++.m4 b/data/c++.m4 index b535cd8f..0fd46e8e 100644 --- a/data/c++.m4 +++ b/data/c++.m4 @@ -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 - ]b4_parser_class_name[::basic_symbol::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 + ]b4_parser_class_name[::basic_symbol::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 ]b4_parser_class_name[::basic_symbol::~basic_symbol ()