From 7eced7335a1f0bc8375d8b84a606dd1456546ac1 Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Sun, 23 Dec 2018 12:02:36 +0100 Subject: [PATCH] work around bison 3.2 bug (fixes #72) --- Rez/RezParser.yy | 13 ++++++++++++- Rez/Test/UnitTests.cc | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Rez/RezParser.yy b/Rez/RezParser.yy index 7563a33036..e7f5259ef0 100644 --- a/Rez/RezParser.yy +++ b/Rez/RezParser.yy @@ -118,7 +118,18 @@ { public: RezSymbol() = default; - RezSymbol(yy::RezParser::symbol_type&& x) : yy::RezParser::symbol_type(std::move(x)) {} + + // Bison 3.2 has a bug in the move constructor for basic_symbol. + // Bison-generated code uses only basic_symbol::move, which + // works without crashing. + RezSymbol(yy::RezParser::symbol_type&& x) + { + move(x); + } + RezSymbol(RezSymbol&& x) + { + move(x); + } }; } diff --git a/Rez/Test/UnitTests.cc b/Rez/Test/UnitTests.cc index a172a34710..fee01c864c 100644 --- a/Rez/Test/UnitTests.cc +++ b/Rez/Test/UnitTests.cc @@ -25,6 +25,28 @@ BOOST_AUTO_TEST_SUITE(LexSuite) BOOST_CHECK_EQUAL(t.token(), TOKEN); \ } while(0) +BOOST_AUTO_TEST_CASE(moveBisonSymbol) +{ + // Bison 3.2 contains a bug in the move constructor for its symbol type. + // It will crash when used. + // Unfortunately, there is no copy constructor any more, so it's hard to avoid. + std::string filename = "foo"; + yy::location loc(&filename, 0,0); + auto sym = RezParser::make_INTLIT(42, loc); + auto sym2 = std::move(sym); +} + +BOOST_AUTO_TEST_CASE(moveRezSymbol) +{ + // This tests my workaround for the bison bug; + // RezSymbol derives from bison's symbol type and reimplements all move constructors + std::string filename = "foo"; + yy::location loc(&filename, 0,0); + RezSymbol sym = RezParser::make_INTLIT(42, loc); + auto sym2 = std::move(sym); +} + + BOOST_AUTO_TEST_CASE(basicInt) { RezWorld world;