From 1113522acb86deec5b4cf75fb40b36a3279813e2 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 15 Aug 2018 15:19:25 +0200 Subject: [PATCH] c++: fix GCC8 warnings about uninitialized values In 0931d14728fb4a2272399f2c927ae78e2607b4fb I removed too many initializations from some ctors: some were not about base ctors, but about member variables. In fact, more of them were missing to please GCC 8. While at it, generate more natural code for C++ without variant: instead of template parser::basic_symbol::basic_symbol (const basic_symbol& other) : Base (other) , value () { value = other.value } generate template parser::basic_symbol::basic_symbol (const basic_symbol& other) : Base (other) , value (other.value) {} * data/c++.m4 (basic_symbol::basic_symbol): Always initialize 'value', it might be a POD without a ctor. * data/lalr1.cc (stack_symbol_type::stack_symbol_type): Likewise. * data/variant.hh (variant::variant): Default initialize the buffer too. --- data/c++.m4 | 18 ++++++++++-------- data/lalr1.cc | 9 ++++----- data/variant.hh | 5 +++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/data/c++.m4 b/data/c++.m4 index 90679345..396d8613 100644 --- a/data/c++.m4 +++ b/data/c++.m4 @@ -296,18 +296,19 @@ m4_define([b4_public_types_define], // basic_symbol. template - ]b4_parser_class_name[::basic_symbol::basic_symbol ()]b4_locations_if([ - : location ()])[ + ]b4_parser_class_name[::basic_symbol::basic_symbol () + : value ()]b4_locations_if([ + , location ()])[ {} template ]b4_parser_class_name[::basic_symbol::basic_symbol (const basic_symbol& other) - : Base (other)]b4_locations_if([ + : Base (other) + , value (]b4_variant_if([], [other.value])[)]b4_locations_if([ , location (other.location)])[ - { - ]b4_variant_if([b4_symbol_variant([other.type_get ()], [value], [copy], - [other.value])], - [value = other.value;])[ + {]b4_variant_if([ + b4_symbol_variant([other.type_get ()], [value], [copy], + [other.value])])[ } template @@ -330,7 +331,8 @@ m4_define([b4_public_types_define], ]b4_parser_class_name[::basic_symbol::basic_symbol (]b4_join( [typename Base::kind_type t], b4_locations_if([const location_type& l]))[) - : Base (t)]b4_locations_if([ + : Base (t) + , value ()]b4_locations_if([ , location (l)])[ {}]])[ diff --git a/data/lalr1.cc b/data/lalr1.cc index 2c99aacf..053875de 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -574,11 +574,10 @@ m4_if(b4_prefix, [yy], [], {} ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (state_type s, symbol_type& that) - : super_type (s]b4_locations_if([, that.location])[) - { - ]b4_variant_if([b4_symbol_variant([that.type_get ()], - [value], [move], [that.value])], - [[value = that.value;]])[ + : super_type (s]b4_variant_if([], [, that.value])[]b4_locations_if([, that.location])[) + {]b4_variant_if([ + b4_symbol_variant([that.type_get ()], + [value], [move], [that.value])])[ // that is emptied. that.type = empty_symbol; } diff --git a/data/variant.hh b/data/variant.hh index 990d14d2..1ffc5b26 100644 --- a/data/variant.hh +++ b/data/variant.hh @@ -94,8 +94,9 @@ m4_define([b4_variant_define], typedef variant self_type; /// Empty construction. - variant ()]b4_parse_assert_if([ - : yytypeid_ (YY_NULLPTR)])[ + variant () + : yybuffer_ ()]b4_parse_assert_if([ + , yytypeid_ (YY_NULLPTR)])[ {} /// Construct and fill.