From 09bc1b99c9a1c6fb4539610ecf5a63f7a3680c31 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 10 Sep 2018 20:01:48 +0200 Subject: [PATCH] lalr1.cc: modern C++ no longer needs an assignment for symbols Reported by Frank Heckenbach. http://lists.gnu.org/archive/html/bug-bison/2018-03/msg00002.html Actually the assignment operator should never be needed: the C++98 requirements for vector::push_back is CopyInsertable, which does not require an assignment operator. However, libstdc++ shipped with GCC up to (and including) 6 uses the assignment operator (which affects Clang on top of libstdc++, but also ICC). So let's keep it for legacy C++. See https://gcc.godbolt.org/z/q0XXmC. * data/lalr1.cc (stack_symbol_type::operator=): Remove. * data/c++.m4 (basic_symbol::operator=): Ditto. * tests/c++.at (C++ Variant-based Symbols Unit Tests): Adjust. --- data/c++.m4 | 2 ++ data/lalr1.cc | 6 +++++- tests/c++.at | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/data/c++.m4 b/data/c++.m4 index 32bf8254..4cf51d40 100644 --- a/data/c++.m4 +++ b/data/c++.m4 @@ -272,8 +272,10 @@ m4_define([b4_symbol_type_declare], location_type location;])[ private: +#if defined __cplusplus && __cplusplus < 201103L /// Assignment operator. basic_symbol& operator= (const basic_symbol& other); +#endif }; /// Type access provider for token (enum) based symbols. diff --git a/data/lalr1.cc b/data/lalr1.cc index 239c242b..15fd6fb9 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -326,8 +326,10 @@ b4_location_define])])[ stack_symbol_type (YY_RVREF (stack_symbol_type) that); /// Steal the contents from \a sym to build this. stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) sym); - /// Assignment, needed by push_back. +#if defined __cplusplus && __cplusplus < 201103L + /// Assignment, needed by push_back by some old implementations. stack_symbol_type& operator= (YY_MOVE_REF (stack_symbol_type) that); +#endif }; /// Stack type. @@ -608,6 +610,7 @@ m4_if(b4_prefix, [yy], [], that.type = empty_symbol; } +#if defined __cplusplus && __cplusplus < 201103L ]b4_parser_class_name[::stack_symbol_type& ]b4_parser_class_name[::stack_symbol_type::operator= (YY_MOVE_REF (stack_symbol_type) that) { @@ -618,6 +621,7 @@ m4_if(b4_prefix, [yy], [], location = YY_MOVE (that.location);])[ return *this; } +#endif template void diff --git a/tests/c++.at b/tests/c++.at index 1b80063b..b92fe9e1 100644 --- a/tests/c++.at +++ b/tests/c++.at @@ -166,12 +166,12 @@ int main() for (int i = 0; i < 100; ++i) { #if defined __cplusplus && 201103L <= __cplusplus - auto ss = parser::stack_symbol_type(1, parser::make_INT(123)); + st.push(parser::stack_symbol_type{1, parser::make_INT(123)}); #else parser::symbol_type s = parser::make_INT(123); parser::stack_symbol_type ss(1, s); -#endif st.push(ss); +#endif } } }