mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
c++: don't use YY_ASSERT at all if parse.assert is disabled
In some extreme situations (about 800 tokens), we generate a
single-line assertion long enough for Visual C++ to discard the end of
the line, thus falling into parse ends for the missing `);`. On a
shorter example:
YY_ASSERT (tok == token::TOK_YYEOF || tok == token::TOK_YYerror || tok == token::TOK_YYUNDEF || tok == token::TOK_ASSIGN || tok == token::TOK_MINUS || tok == token::TOK_PLUS || tok == token::TOK_STAR || tok == token::TOK_SLASH || tok == token::TOK_LPAREN || tok == token::TOK_RPAREN);
Whether NDEBUG is used or not is irrelevant, the parser dies anyway.
Reported by Jot Dot <jotdot@shaw.ca>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00002.html
We should avoid emitting lines so long.
We probably should also use a range-based assertion (with extraneous
parens to pacify fascist compilers):
YY_ASSERT ((token::TOK_YYEOF <= tok && tok <= token::TOK_YYUNDEF)
|| (token::TOK_ASSIGN <= tok && ...)
But anyway, we should simply not emit this assertion at all when not
asked for.
* data/skeletons/variant.hh: Do not define, nor use, YY_ASSERT when it
is not enabled.
This commit is contained in:
8
NEWS
8
NEWS
@@ -4,9 +4,17 @@ GNU Bison NEWS
|
|||||||
|
|
||||||
** Bug fixes
|
** Bug fixes
|
||||||
|
|
||||||
|
*** Bug fixes in yacc.c
|
||||||
|
|
||||||
In Yacc mode, all the tokens are defined twice: once as an enum, and then
|
In Yacc mode, all the tokens are defined twice: once as an enum, and then
|
||||||
as a macro. YYEMPTY was missing its macro.
|
as a macro. YYEMPTY was missing its macro.
|
||||||
|
|
||||||
|
*** Bug fixes in lalr1.cc
|
||||||
|
|
||||||
|
The lalr1.cc skeleton used to emit internal assertions (using YY_ASSERT)
|
||||||
|
even when the `parse.assert` %define variable is not enabled. It no
|
||||||
|
longer does.
|
||||||
|
|
||||||
** Changes
|
** Changes
|
||||||
|
|
||||||
The YYBISON macro in generated "regular C parsers" (from the "yacc.c"
|
The YYBISON macro in generated "regular C parsers" (from the "yacc.c"
|
||||||
|
|||||||
@@ -71,12 +71,12 @@ m4_map([ b4_symbol_tag_comment], [$@])dnl
|
|||||||
# -------------------
|
# -------------------
|
||||||
# The needed includes for variants support.
|
# The needed includes for variants support.
|
||||||
m4_define([b4_variant_includes],
|
m4_define([b4_variant_includes],
|
||||||
[b4_parse_assert_if([[#include <typeinfo>]])[
|
[b4_parse_assert_if([[#include <typeinfo>
|
||||||
#ifndef YY_ASSERT
|
#ifndef YY_ASSERT
|
||||||
# include <cassert>
|
# include <cassert>
|
||||||
# define YY_ASSERT assert
|
# define YY_ASSERT assert
|
||||||
#endif
|
#endif
|
||||||
]])
|
]])])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -110,8 +110,8 @@ m4_define([b4_value_type_declare],
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
semantic_type (YY_RVREF (T) t)]b4_parse_assert_if([
|
semantic_type (YY_RVREF (T) t)]b4_parse_assert_if([
|
||||||
: yytypeid_ (&typeid (T))])[
|
: yytypeid_ (&typeid (T))])[
|
||||||
{
|
{]b4_parse_assert_if([[
|
||||||
YY_ASSERT (sizeof (T) <= size);
|
YY_ASSERT (sizeof (T) <= size);]])[
|
||||||
new (yyas_<T> ()) T (YY_MOVE (t));
|
new (yyas_<T> ()) T (YY_MOVE (t));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,9 +410,6 @@ m4_define([_b4_token_constructor_define],
|
|||||||
: super_type(]b4_join([token_type (tok)],
|
: super_type(]b4_join([token_type (tok)],
|
||||||
b4_symbol_if([$1], [has_type], [std::move (v)]),
|
b4_symbol_if([$1], [has_type], [std::move (v)]),
|
||||||
b4_locations_if([std::move (l)]))[)
|
b4_locations_if([std::move (l)]))[)
|
||||||
{
|
|
||||||
YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
symbol_type (]b4_join(
|
symbol_type (]b4_join(
|
||||||
[int tok],
|
[int tok],
|
||||||
@@ -422,10 +419,10 @@ m4_define([_b4_token_constructor_define],
|
|||||||
: super_type(]b4_join([token_type (tok)],
|
: super_type(]b4_join([token_type (tok)],
|
||||||
b4_symbol_if([$1], [has_type], [v]),
|
b4_symbol_if([$1], [has_type], [v]),
|
||||||
b4_locations_if([l]))[)
|
b4_locations_if([l]))[)
|
||||||
{
|
|
||||||
YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
{]b4_parse_assert_if([[
|
||||||
|
YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
|
||||||
|
]])[}
|
||||||
]])])
|
]])])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user