autocxx icon indicating copy to clipboard operation
autocxx copied to clipboard

Avoid the `std::move` for each value parameter

Open adetaylor opened this issue 3 years ago • 5 comments

It would be good to impl ValueParam<T> for any New<Output=T>.

In addition, somewhere deep in the generated bindings, we still currently call std::move on the C++ side. This is probably not desirable.

adetaylor avatar Mar 03 '22 01:03 adetaylor

#847 is an attempt at addressing this.

adetaylor avatar Mar 03 '22 01:03 adetaylor

One bad thing that the std::move does: C++ methods which take a non-const reference don't work. I get compile errors like this:

bazel-out/k8-fastbuild/bin/aos/events/event_loop_rs__gen__dir/gen0.h:64:160: error: 
      non-const lvalue reference to type 'flatbuffers::Verifier' cannot bind to a temporary of type
      'typename std::remove_reference<Verifier &>::type' (aka 'flatbuffers::Verifier')
  ...arg1)  { return std::move(autocxx_gen_this).Verify(std::move(arg1)); }

The method signature being wrapped is bool Verify(flatbuffers::Verifier &verifier) const;.

bsilver8192 avatar Mar 03 '22 08:03 bsilver8192

Half of this is now done in #847; the remaining half is to remove the std::move.

adetaylor avatar Mar 08 '22 23:03 adetaylor

@bsilver8192 Could you perhaps add a test case for the problem you report above? I tried in https://github.com/google/autocxx/pull/900 but it all seems to work, so I must be doing something slightly differently.

adetaylor avatar Mar 09 '22 01:03 adetaylor

Ok, added a PR. The tricky thing is it works if it's the only method with a given name, because then it doesn't get an autocxx-generated C++ wrapper, and bindgen/cxxbridge manages calling it fine.

Not sure you want to just fix it immediately, or disable those tests, or add duplicated tests that are disabled, up to you.

bsilver8192 avatar Mar 09 '22 23:03 bsilver8192