Hans Åberg wrote: > >> Ah, your idea is to wrap std::move around the $k values! My idea > >> is to let the C++ language recognise that, and then automate the > >> assignment to $$. > > > > Again, the assignment to $$ is <bold>*NOT*</bold> the issue! (*) > > It's the passing (moving) of $k. > > > > (*) Nitpick: Except in a case like "$$ = $2;", but then I'd argue > > it's the passing of $2 to $$'s assignment operator that's the > > issue. :) > > Maybe not for you, but for a more normal use, with types having > both copy and move. Then one would like to use move to $$ whenever > possible. Doesn't matter with me, as it is just some pointers and > integers.
As I said, this already happens in "$$ = foo ();" (automatially) and "$$ = std::move ($k);" (whether the move is explicit or automatically inserted as we're discussing). So if $k is covered, no special handling for $$ seems necessary. > > You mean some kind of code analyzer? This might be possible, but may > > be overkill. > > Yes, you might check how people do check against that problem, if > there is some program doing that. Then one might get ideas of how > to get into Bison. > > Perhaps it might be possible to have some DLL or external program and invoke > that. If you know of one, let me know. (And it would have to be GPL-compatible in order to link it into Bison.) > No, but it seems me it is a hard problem. A compiler optimizer can > recognize such things if it has sufficient information about the > types, by tracing the code flow. Yes, perhaps we should ignore the issue for now and hope for compilers to offer such a warning in the future (which would be more useful anyway, since it would work for all code, not only Bison grammars). > > On the same token, Bison could then also (optionally) warn if some > > $k which has a type is not used. I don't know if there is interest > > in such a feature. It could also be useful for other languages. > > > > It might not be too hard to do for someone who's familiar with > > Bison's internals. (Unfortunately, I'm not very much, and don't have > > much free time right now.) > > How would this be different from the current static type system? The type system wouldn't change. Just an additional check: expr: expr '+' expr { $$ = $1; }; Obviously one forgot to use $3 here which has a type (unlike $2 which doesn't have a type and so is not expected to be used). Bison could detect and warn about this (proably optional, since I guess some people declare semantic types that are only meant to be used sometimes). Regards, Frank