> On 15 Sep 2018, at 20:19, Frank Heckenbach <[email protected]> wrote: > > Hans Åberg wrote: > >> One idea might be to wrap the actions in inlines, and use return instead, as >> C++ can recognize r-values in such situations. > > I think we discussed this before, but this would only cover the case > "$$ = $N" (which is covered by the default action for N = 1 anyway). > > More interesting are cases such as: > > $$ = make_unique <foo> ($1, $2, $3);
The idea would be to write something equivalent to return make_unique<foo>($1, $2, $3); and the Bison writes something like $$ = std::move(action_k(…return make_unique<foo>($1, $2, $3);…)) Even in view of copy elision, default in C++17 [1], this would be safe, because one cannot move an already moved object by mistake. As the point is breaking out of the execution path, one might use your suggestion of a special operator in combination with an immediately following break in the action switch statement. So writing say $$$(make_unique<foo>($1, $2, $3)); translates into $$ = std::move(make_unique<foo>($1, $2, $3)); break; 1. https://en.cppreference.com/w/cpp/language/copy_elision
