Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_take_as_pod_with_is_relocatable fails with wrappers forced #1252

Open
adetaylor opened this issue Feb 20, 2023 · 1 comment
Open

test_take_as_pod_with_is_relocatable fails with wrappers forced #1252

adetaylor opened this issue Feb 20, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@adetaylor
Copy link
Collaborator

With the branch in #1250, test_take_as_pod_with_is_relocatable fails:

RUST_LOG=autocxx_engine=info AUTOCXX_FORCE_WRAPPER_GENERATION=1  cargo test test_take_as_pod_with_is_relocatable -- --nocapture
running: "c++" "-O1" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-I" "/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv" "-I" "/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv/target/include" "-I" "/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv" "-Wall" "-Wextra" "-std=c++14" "-Wall" "-Werror" "-o" "/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv/target/cxx/gen0.o" "-c" "/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv/target/cxx/gen0.cxx"
cargo:warning=In file included from /var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv/target/cxx/gen0.cxx:2:
cargo:warning=/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv/target/include/autocxxgen_ffi.h:45:90: error: call to implicitly-deleted copy constructor of 'Bob'
cargo:warning=inline uint32_t take_bob_autocxx_wrapper_0x7ae9fb9c423cc5ae(Bob arg0)  { return take_bob(arg0); }
cargo:warning=                                                                                         ^~~~
cargo:warning=/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv/input.h:9:12: note: copy constructor is implicitly deleted because 'Bob' has a user-declared move constructor
cargo:warning=    inline Bob(Bob&& other_bob) { a = other_bob.a; b = other_bob.b; }
cargo:warning=           ^
cargo:warning=/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv/input.h:12:23: note: passing argument to parameter 'a' here
cargo:warning=uint32_t take_bob(Bob a);
cargo:warning=                      ^
cargo:warning=1 error generated.
exit status: 1
thread 'integration_test::test_take_as_pod_with_is_relocatable' panicked at 'called `Result::unwrap()` on an `Err` value: CppBuild(Error { kind: ToolExecError, message: "Command \"c++\" \"-O1\" \"-ffunction-sections\" \"-fdata-sections\" \"-fPIC\" \"-arch\" \"arm64\" \"-I\" \"/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv\" \"-I\" \"/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv/target/include\" \"-I\" \"/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv\" \"-Wall\" \"-Wextra\" \"-std=c++14\" \"-Wall\" \"-Werror\" \"-o\" \"/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv/target/cxx/gen0.o\" \"-c\" \"/var/folders/3w/3pyz6m7s1jn5dlm38v01w54h0000gp/T/.tmp3eWnBv/target/cxx/gen0.cxx\" with args \"c++\" did not execute successfully (status code exit status: 1)." })', integration-tests/tests/integration_test.rs:529:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test integration_test::test_take_as_pod_with_is_relocatable ... FAILED
@adetaylor adetaylor added the bug Something isn't working label Feb 20, 2023
@adetaylor
Copy link
Collaborator Author

It's not quite clear what to do about this.

If Bob is declared as non-POD, we generate:

inline uint32_t take_bob_autocxx_wrapper_0xfd37c8511aecb2b1(Bob* arg0)  { return take_bob(std::move(*arg0)); }

If Bob is declared as POD, we generate:

inline uint32_t take_bob_autocxx_wrapper_0x7ae9fb9c423cc5ae(Bob arg0)  { return take_bob(arg0); }

which is reasonable for any type which is truly trivially relocatable. This type has a non-trivial move constructor but specifies using IsRelocatable = std::true_type; which is how we can use it with generate_pod!

Still, passing by value (without std::move) is preferable for truly POD types.

At code generation time, we can't know whether a type has using IsRelocatable = std::true_type; as opposed to a trivial move constructor.

So, our options are:

  • Some kind of RAII template voodoo where we generate the same code each time, but it boils down to move-by-value where possible, or std::move otherwise.
  • Some additional directive for folks to teach autocxx that a type always requires std::move.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant