Support passing Carbon Optional(T*) to C++ T* parameter. (#6422)

We already did this translation in the other direction, but we had no
mapping from `Optional(T)` to anything, so round-tripping a nullable
pointer from C++ through Carbon and back to C++ was previously rejected.
This commit is contained in:
Richard Smith
2025-11-25 22:30:14 +00:00
committed by GitHub
parent 6b775b3014
commit ec8c999bb1
8 changed files with 472 additions and 120 deletions
+2 -3
View File
@@ -27,10 +27,9 @@ fn HelloPutchar() {
// Demonstrate passing a null-terminated string to a C++ function.
fn HelloStdio() {
// TODO: Requires mapping from Optional(const char*) into C++.
// TODO: There should be a better way to interact with functions that expect a
// null-terminated string.
// Cpp.puts(Cpp.std.data("Hello world!\n\0"));
Cpp.puts(Cpp.std.data("Hello world!\0"));
// TODO: Requires variadic function support.
// Cpp.printf("Hello world!\n\0");
@@ -38,7 +37,7 @@ fn HelloStdio() {
// Demonstrate passing a string as a void pointer to a C++ function.
fn HelloWrite() {
// TODO: Requires mapping from Optional(const char*) into a C++ const void*.
// 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));
}