Open j-baker opened 1 year ago
Commenting so I can follow the ticket's progress as I'm getting the same issue.
At other places, return types are indirected, here not. Probably it would be helpful to convert the bridge to C++ linkage instead of C linkage.
The warning tells you that there may be ABI incompatibilities. However, as long as you compile and link with the same compiler/linker, you should be on the safe side. Nevertheless, it's still sort-of undefined behavior. We do suppress the warning in our project. Here is the comment from our makefile:
# Using template types in the Rust client lib leads to warnings emitted by `clang` because
# technically the interface defines functions as `extern "C"` (necessary because of name
# mangling). Strictly speaking, those template types are not allowed in return types. Disabling
# the warning is a hack. Note that `gcc` does not know this warning.
Is there any non-hacky way to solve this? What would it take to make cxx not emit 'sort-of undefined behavior'?
Is there any non-hacky way to solve this? What would it take to make cxx not emit 'sort-of undefined behavior'?
I suppose there is none, as of now. Theoretically, you could wrap a specific instantiation of Rust generic (i.e., with fixed type argument) in a newtype without generic and pass that, but passing arbitrary Rust types between C/C++ is also not supported as of now (only in the patches in our private fork).
But as I wrote almost a year ago, this should be no big issue in practice and you can safely ignore the warning, if the compiler/linker version on both sides generates the same layout for rust::Vec<T>
(RustVec<T>
on the Rust side is marked with #[repr(C)]
, so it should always be the case for POD T
).
Hi! I have project where I'm trying to expose an 'interface' on the Rust side for C++ to implement. This exposes a C++ header and opaque type which looks something like
Essentially, it takes a function pointer to an operation implemented in Rust. It's exposed in Rust as
While this code empirically works, when compiling it issues a warning, complaining that:
Is this related to my declaration or is it a limitation of CXX right now? Is anything bad going to happen? Like I assume many of you, I'm much more familiar with Rust than C++.