google / autocxx

Tool for safe ergonomic Rust/C++ interop driven from existing C++ headers
https://docs.rs/autocxx
Apache License 2.0
2.25k stars 144 forks source link

Codegen results in function call with incorrect number of arguments #1342

Open paulyoung opened 1 year ago

paulyoung commented 1 year ago

Describe the bug The build fails with the following:

cargo:warning=In file included from /Users/py/projects/paulyoung/autocxx-bug/main/target/debug/build/autocxx-bug-94a6f68b4aecae68/out/autocxx-build-dir/cxx/gen0.cxx:2:

cargo:warning=/Users/py/projects/paulyoung/autocxx-bug/main/target/debug/build/autocxx-bug-94a6f68b4aecae68/out/autocxx-build-dir/include/autocxxgen_ffi.h:57:144: error: no matching function for call to 'operator new'

cargo:warning=inline void MySubclassCpp_new_autocxx_autocxx_wrapper_0xc63676881d849a16(MySubclassCpp* autocxx_gen_this, rust::Box<MySubclassHolder> arg1)  { new (autocxx_gen_this) MySubclassCpp(std::move(arg1)); }

cargo:warning=                                                                                                                                               ^   ~~~~~~~~~~~~~~~~~~

cargo:warning=include/MyClass.h:12:15: note: candidate function not viable: requires single argument 'size', but 2 arguments were provided

cargo:warning=        static void* operator new( size_t size );

cargo:warning=                     ^

To Reproduce Try to build the project at https://github.com/paulyoung/autocxx-bug

Expected behavior Codegen results in code supplying the correct number of arguments.

Additional context In reality I don't control the header files so any potential workarounds would preferably not involve modifying them.

paulyoung commented 1 year ago

I just updated the repo to use generate! instead of subclass! since I figured that would be a more minimal example, even though my use case is subclassing.

The build now fails with:

cargo:warning=In file included from /Users/py/projects/paulyoung/autocxx-bug/main/target/debug/build/autocxx-bug-94a6f68b4aecae68/out/autocxx-build-dir/cxx/gen0.cxx:2:

cargo:warning=/Users/py/projects/paulyoung/autocxx-bug/main/target/debug/build/autocxx-bug-94a6f68b4aecae68/out/autocxx-build-dir/include/autocxxgen_ffi.h:43:148: error: no matching function for call to 'operator new'

cargo:warning=inline void new_synthetic_const_copy_ctor_0x42aaa771a89cc55d_autocxx_wrapper_0x42aaa771a89cc55d(MyClass* autocxx_gen_this, const MyClass& arg1)  { new (autocxx_gen_this) MyClass(arg1); }

cargo:warning=                                                                                                                                                   ^   ~~~~~~~~~~~~~~~~~~

cargo:warning=include/MyClass.h:12:15: note: candidate function not viable: requires single argument 'size', but 2 arguments were provided

cargo:warning=        static void* operator new( size_t size );

cargo:warning=                     ^
stevefan1999-personal commented 10 months ago

Here's a concrete real life example (attemping to use autocxx with Half-Life SDK) stevefan1999-personal/autocxx-bug-operator-new (github.com)

pevers commented 6 months ago

I just updated the repo to use generate! instead of subclass! since I figured that would be a more minimal example, even though my use case is subclassing.

The build now fails with:

cargo:warning=In file included from /Users/py/projects/paulyoung/autocxx-bug/main/target/debug/build/autocxx-bug-94a6f68b4aecae68/out/autocxx-build-dir/cxx/gen0.cxx:2:

cargo:warning=/Users/py/projects/paulyoung/autocxx-bug/main/target/debug/build/autocxx-bug-94a6f68b4aecae68/out/autocxx-build-dir/include/autocxxgen_ffi.h:43:148: error: no matching function for call to 'operator new'

cargo:warning=inline void new_synthetic_const_copy_ctor_0x42aaa771a89cc55d_autocxx_wrapper_0x42aaa771a89cc55d(MyClass* autocxx_gen_this, const MyClass& arg1)  { new (autocxx_gen_this) MyClass(arg1); }

cargo:warning=                                                                                                                                                   ^   ~~~~~~~~~~~~~~~~~~

cargo:warning=include/MyClass.h:12:15: note: candidate function not viable: requires single argument 'size', but 2 arguments were provided

cargo:warning=        static void* operator new( size_t size );

cargo:warning=                     ^

Hi @paulyoung , did you manage to solve this in the end? I'm also running into this issue.

paulyoung commented 6 months ago

@pevers I didn't.

I thought about trying to fix the issue and submitting a PR or writing something by hand instead but my project is fairly low priority so I haven't invested any more time into it.

paulyoung commented 6 months ago

I might at least add some failing test cases.