Pass Str in PtrLen representation
MSVC is hesitant about passing private fields in an extern "C" signature.
Repro:
struct Str1 {
const char *ptr;
size_t len;
};
struct Str2 {
private:
const char *ptr;
size_t len;
};
extern "C" {
Str1 str1();
Str2 str2();
}
Warning from MSVC v19.27:
warning C4190: 'str2' has C-linkage specified, but returns UDT 'Str2' which is incompatible with C
diff --git a/include/cxx.h b/include/cxx.h
index de614d1..220f45f 100644
--- a/include/cxx.h
+++ b/include/cxx.h
@@ -79,6 +79,7 @@
~Str() noexcept = default;
private:
+ friend impl<Str>;
// Not necessarily ABI compatible with &str. Codegen will translate to
// cxx::rust_str::RustStr which matches this layout.
const char *ptr;