-
Notifications
You must be signed in to change notification settings - Fork 77
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
Clang 17 return-type-c-linkage warning in qml-features #853
Comments
@LeonMatthesKDAB any ideas what might be wrong here, looks like your constructor code is declaring a CXX method returning a shared struct ? |
That's just a shared CXX type, so might be a CXX issue. 🤔 |
So investigating this I've found it is linked to using references in the shared struct. If they are a pointer or a value the warning does not occur. @LeonMatthesKDAB wondered if we could automatically convert between reference and pointer when required. Code with a reference#[cxx::bridge]
mod ffi {
struct SharedStruct<'a> {
value: &'a u32,
}
extern "Rust" {
fn test2() -> SharedStruct<'static>;
}
}
fn test2() -> ffi::SharedStruct<'static> {
ffi::SharedStruct { value: &2 }
}
fn main() {
println!("Hello, world!");
let shared2 = test2();
println!("Shared: {}", shared2.value);
} If you run this with a recent clang version the following occurs $ CC=clang CXX=clang++ cargo run
warning: [email protected]: /var/home/andrew/Projects/cxx/sharedtype/target/debug/build/sharedtype-d22b5f580a4bbff5/out/cxxbridge/sources/sharedtype/src/main.rs.cc:16:16: warning: 'cxxbridge1$test2' has C-linkage specified, but returns user-defined type '::SharedStruct' which is incompatible with C [-Wreturn-type-c-linkage]
warning: [email protected]: 16 | ::SharedStruct cxxbridge1$test2() noexcept;
warning: [email protected]: | ^
warning: [email protected]: 1 warning generated.
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s
Running `target/debug/sharedtype`
Hello, world!
Shared: 2 Code with a pointer#[cxx::bridge]
mod ffi {
struct SharedStruct {
value: *mut u32,
}
extern "Rust" {
fn test2() -> SharedStruct;
}
}
fn test2() -> ffi::SharedStruct {
ffi::SharedStruct {
value: Box::into_raw(Box::new(2)),
}
}
fn main() {
println!("Hello, world!");
let shared2 = test2();
println!("Shared: {:?}", unsafe { shared2.value.as_mut() });
} If you use a pointer it is fine though (and it also works for just $ CC=clang CXX=clang++ cargo run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/sharedtype`
Hello, world!
Shared: Some(2) |
The text was updated successfully, but these errors were encountered: