Compare commits

...
6 Commits
Author SHA1 Message Date
Akim Demaille 8adec9c125 version 3.2.4
* NEWS: Record release date.
2018-12-24 17:45:02 +01:00
Akim Demaille cafa811a66 c++: also provide a copy constructor for symbol_type
Suggested by Wolfgang Thaller.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00081.html

* data/c++.m4 (basic_symbol, by_type): Instead of provide either move
or copy constructor, always provide the copy one.
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Check it.
2018-12-24 11:30:13 +01:00
Akim Demaille 07a187c5ee c++: fix double free when a symbol_type was moved
Currently the following piece of code crashes (with parse.assert),
because we don't record that s was moved-from, and we invoke its dtor.

    {
      auto s = parser::make_INT (42);
      auto s2 = std::move (s);
    }

Reported by Wolfgang Thaller.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00077.html

* data/c++.m4 (by_type): Provide a move-ctor.
(basic_symbol): Be sure not to read a moved-from value.
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Check this case.
2018-12-24 07:49:50 +01:00
Akim Demaille a81bcbb245 c++: style: improve tests
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Provide better
assertions.
Use them.
Avoid useless Bison invocations.
2018-12-24 07:49:50 +01:00
Akim Demaille 96ef81cf07 c++: style: use consistently this/that instead of this/other
* data/c++.m4: here.
2018-12-23 19:39:47 +01:00
Akim Demaille fc54e6b9b3 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2018-12-18 23:07:55 +01:00
5 changed files with 91 additions and 26 deletions
+1 -1
View File
@@ -1 +1 @@
3.2.2
3.2.3
+8
View File
@@ -1,5 +1,13 @@
GNU Bison NEWS
* Noteworthy changes in release 3.2.4 (2018-12-24) [stable]
** Bug fixes
Fix the move constructor of symbol_type.
Always provide a copy constructor for symbol_type, even in modern C++.
* Noteworthy changes in release 3.2.3 (2018-12-18) [stable]
** Bug fixes
+1
View File
@@ -179,6 +179,7 @@ Wayne Green [email protected]
Wei Song [email protected]
Wojciech Polak [email protected]
Wolfgang S. Kechel [email protected]
Wolfgang Thaller [email protected]
Wolfram Wagner [email protected]
Wwp [email protected]
xolodho [email protected]
+42 -12
View File
@@ -244,8 +244,13 @@ m4_define([b4_symbol_type_declare],
/// Default constructor.
basic_symbol ();
/// Move or copy constructor.
basic_symbol (YY_RVREF (basic_symbol) other);
#if 201103L <= YY_CPLUSPLUS
/// Move constructor.
basic_symbol (basic_symbol&& that);
#endif
/// Copy constructor.
basic_symbol (const basic_symbol& that);
]b4_variant_if([[
/// Constructor for valueless symbols, and symbols from each type.
@@ -280,7 +285,7 @@ m4_define([b4_symbol_type_declare],
private:
#if YY_CPLUSPLUS < 201103L
/// Assignment operator.
basic_symbol& operator= (const basic_symbol& other);
basic_symbol& operator= (const basic_symbol& that);
#endif
};
@@ -290,8 +295,13 @@ m4_define([b4_symbol_type_declare],
/// Default constructor.
by_type ();
#if 201103L <= YY_CPLUSPLUS
/// Move constructor.
by_type (by_type&& that);
#endif
/// Copy constructor.
by_type (const by_type& other);
by_type (const by_type& that);
/// The symbol type as needed by the constructor.
typedef token_type kind_type;
@@ -339,14 +349,26 @@ m4_define([b4_public_types_define],
, location ()])[
{}
#if 201103L <= YY_CPLUSPLUS
template <typename Base>
]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (YY_RVREF (basic_symbol) other)
: Base (YY_MOVE (other))
, value (]b4_variant_if([], [YY_MOVE (other.value)]))b4_locations_if([
, location (YY_MOVE (other.location))])[
]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (basic_symbol&& that)
: Base (std::move (that))
, value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([
, location (std::move (that.location))])[
{]b4_variant_if([
b4_symbol_variant([other.type_get ()], [value], [YY_MOVE_OR_COPY],
[YY_MOVE (other.value)])])[
b4_symbol_variant([this->type_get ()], [value], [move],
[std::move (that.value)])])[
}
#endif
template <typename Base>
]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (const basic_symbol& that)
: Base (that)
, value (]b4_variant_if([], [that.value]))b4_locations_if([
, location (that.location)])[
{]b4_variant_if([
b4_symbol_variant([this->type_get ()], [value], [copy],
[that.value])])[
}
]b4_variant_if([[
@@ -423,8 +445,16 @@ m4_define([b4_public_types_define],
: type (empty_symbol)
{}
]b4_inline([$1])b4_parser_class_name[::by_type::by_type (const by_type& other)
: type (other.type)
#if 201103L <= YY_CPLUSPLUS
]b4_inline([$1])b4_parser_class_name[::by_type::by_type (by_type&& that)
: type (that.type)
{
that.clear ();
}
#endif
]b4_inline([$1])b4_parser_class_name[::by_type::by_type (const by_type& that)
: type (that.type)
{}
]b4_inline([$1])b4_parser_class_name[::by_type::by_type (token_type t)
+39 -13
View File
@@ -103,7 +103,7 @@ AT_KEYWORDS([variant])
AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc" %debug $1])
# Store strings and integers in a vector of strings.
AT_DATA_GRAMMAR([list.y],
AT_DATA_GRAMMAR([list.yy],
[[%skeleton "lalr1.cc"
%define api.value.type variant
%define parse.assert
@@ -142,24 +142,52 @@ exp: "int" { $$.push_back ($1); }
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE[
template <typename Exp, typename Eff>
void assert_eq (const Exp& exp, const Eff& eff)
{
if (getenv ("DEBUG"))
std::cerr << "Assert: " << exp << " == " << eff << '\n';
if (exp != eff)
std::cerr << "Assertion failed: " << exp << " != " << eff << '\n';
}
int main()
{
using yy::parser;
// symbol_type: construction, accessor.
{
parser::symbol_type s = parser::make_INT(12);
std::cerr << s.value.as<int>() << '\n';
parser::symbol_type s = parser::make_INT (12);
assert_eq (s.value.as<int> (), 12);
}
// symbol_type: move constructor.
#if 201103L <= YY_CPLUSPLUS
{
auto s = parser::make_INT (42);
auto s2 = std::move (s);
assert_eq (s2.value.as<int> (), 42);
// Used to crash here, because s was improperly cleared, and
// its destructor tried to delete its (moved) value.
}
#endif
// symbol_type: copy constructor.
{
parser::symbol_type s = parser::make_INT (51);
parser::symbol_type s2 = s;
assert_eq (s.value.as<int> (), 51);
assert_eq (s2.value.as<int> (), 51);
}
// stack_symbol_type: construction, accessor.
{
#if defined __cplusplus && 201103L <= __cplusplus
#if 201103L <= YY_CPLUSPLUS
auto ss = parser::stack_symbol_type(1, parser::make_INT(123));
#else
parser::symbol_type s = parser::make_INT(123);
parser::symbol_type s = parser::make_INT (123);
parser::stack_symbol_type ss(1, s);
#endif
std::cerr << ss.value.as<int>() << '\n';
assert_eq (ss.value.as<int> (), 123);
}
// Pushing on the stack.
@@ -170,7 +198,7 @@ int main()
const int mucho = 1700;
for (int i = 0; i < mucho; ++i)
{
#if defined __cplusplus && 201103L <= __cplusplus
#if 201103L <= YY_CPLUSPLUS
st.push(parser::stack_symbol_type{1, parser::make_INT (i)});
#else
parser::symbol_type s = parser::make_INT (i);
@@ -180,19 +208,17 @@ int main()
}
for (int i = mucho - 1; 0 <= i; --i)
{
assert (st[0].value.as<int>() == i);
assert_eq (st[0].value.as<int>(), i);
st.pop ();
}
}
}
]])
AT_BISON_CHECK([[-o list.cc list.yy]])
AT_FOR_EACH_CXX([
AT_FULL_COMPILE([list])
AT_PARSER_CHECK([./list], 0, [],
[12
123
])
AT_COMPILE_CXX([list])
AT_PARSER_CHECK([./list])
])
AT_BISON_OPTION_POPDEFS