Allow conversion between T* and Cpp.void*. (#6575)

Support an implicit conversion from `T*` to `Cpp.void*` and to `const
Cpp.void*`, and an `unsafe as` conversion in the opposite direction.

In order to support C++ calls taking and returning `void*` (which get
mapped to Carbon `Optional(Cpp.void*)`, also support conversions from
`Optional(T)` to `Optional(U)` if there's a conversion from `T` to `U`.

Fix a bug in `OptionalStorage` for `T*` where its `HasValue` was exactly
backwards.
This commit is contained in:
Richard Smith
2026-01-12 16:32:15 +00:00
committed by GitHub
parent d1b13194d5
commit 31919afa24
31 changed files with 986 additions and 381 deletions
+2 -3
View File
@@ -37,9 +37,8 @@ fn HelloStdio() {
// Demonstrate passing a string as a void pointer to a C++ function.
fn HelloWrite() {
// TODO: Requires conversion from `const char*` to `const void*`.
// let s: str = "Hello world!\n";
// Cpp.write(1, Cpp.std.data(s), Cpp.std.size(s));
let s: str = "Hello world!\n";
Cpp.write(1, Cpp.std.data(s), Cpp.std.size(s));
}
fn HelloIostreams() {