Re: C++ token move constructors/assignment with LALR

Frank Heckenbach <[email protected]> Fri, 22 Apr 2022 02:31:17 +0200
Newsgroups gmane.comp.parsers.bison.bugs
Message-ID <E1nhhCf-001wkM-MO@mars>
Anthony Heading wrote:

> Totally right, yes it is only the move assignment which was missing / now hidden,  and that's actually the most immediate problem.   Assuming of course it's agreed to be a problem at all,  as I concur the skeleton doesn't use it.    I think the issue arises if the user wants to assign the tokens (which I think is natural, e.g. for lexer putback and so on) and starts even with simple types.
> 
> int main() {
>     parser::symbol_type sym;
>     sym = yylex();
>     return 0;
> }
>
> So because there is no move assignment operator,  C++ tried to fall back to (implicit) copy assignment, but it can't even manage that because there IS a move constructor.

I see. My lexers don't contain any move-assignment, so I never
noticed, but if I add one, I get the same error.

In the example above, of course, it's easy to avoid by replacing

  parser::symbol_type sym;
  sym = yylex();

with

  auto sym = yylex();

but that won't work in every case.

> Enabling the move assignment operator in the skeleton fixes this,  and works for unique_ptr etc too.

Seems useful. If you can make a patch and send it here, or if that's
easy for you, make a pull request on https://github.com/akimd/bison/
or upload on Savannah Git, it'll hopefully be easy for Akim to merge.

Viele Grüße,
Frank