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

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

Open
paulyoung opened this issue Nov 12, 2023 · 5 comments
Open

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

paulyoung opened this issue Nov 12, 2023 · 5 comments

Comments

@paulyoung
Copy link

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
Copy link
Author

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
Copy link

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

@pevers
Copy link

pevers commented May 11, 2024

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
Copy link
Author

@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
Copy link
Author

I might at least add some failing test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants