[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

assertion failure / double destruction triggered by parser::symbol_type'

From: Wolfgang Thaller
Subject: assertion failure / double destruction triggered by parser::symbol_type's move constructor
Date: Sun, 23 Dec 2018 12:21:24 +0100

In bison 3.2.3, given a parser definition that starts like this:

%require "3.0.2"
%define parser_class_name {RezParser}
%skeleton "lalr1.cc"


%define api.token.constructor
%define api.value.type variant
%define parse.assert

%token<int> INTLIT;

the following code crashes:

    std::string filename = "foo";
    yy::location loc(&filename, 0,0);
    auto sym = RezParser::make_INTLIT(42, loc);
    auto sym2 = std::move(sym);

Assertion failed: (yytypeid_), function as, file 
line 370.

The reason is that variant::destroy<int> gets called twice.
When basic_symbol<by_type>::move is used, variant::move is invoked, which 
destroys the source, and by_type::move is invoked, which resets the source’s 
type to empty.
When basic_symbol’s move constructor is used, variant::move is invoked as well, 
but by_type’s constructor is used. Because by_type has no move constructor, it 
never resets the source object’s type to empty, and so the variant will be 
desrtroyed again when basic_symbol’s destructor is invoked.

Suggested fix: by_type needs a move constructor that acts like by_type::move.

I also suggest that the fact that yy:: parser_class_name::symbol_type is no 
longer copy-constructible in bison 3.2 should be listed as a breaking change 
from bison 3.0.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]