mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-20 21:46:43 +00:00
Don't attempt to defer overload resolution by creating a `CppOverloadSet`; this was incorrect as we weren't saving the complete clang::OverloadCandidateSet, resulting in template candidates not being found. Moreover, saving the overload candidate set would be expensive, as the representation is surprisingly large, and is unnecessary since we're about to build a call. In passing, improve the diagnostics for overload resolution failure to use Clang's operator overload resolution messages rather than its call overload resolution messages. This fixes calls to templated operator overloads, which is the final piece needed for us to successfully compile an iostream-based "Hello world" program. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
56 lines
1.6 KiB
Plaintext
56 lines
1.6 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
import Cpp library "<cstdio>";
|
|
import Cpp library "<iostream>";
|
|
import Cpp library "<string_view>";
|
|
import Cpp library "<unistd.h>";
|
|
|
|
// Demonstrate passing `char`s to a C++ function.
|
|
fn HelloPutchar() {
|
|
let message: array(char, 13) =
|
|
('H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\n');
|
|
for (c: char in message) {
|
|
// TODO: u8 should probably have an implicit cast to i32.
|
|
Cpp.putchar((c as u8) as i32);
|
|
}
|
|
|
|
// TODO: Use a loop over a string literal instead. Requires IndexWith support
|
|
// for str.
|
|
//
|
|
// let message: str = "Hello world!\n";
|
|
// for (c: char in message) {
|
|
// Cpp.putchar((c as u8) as i32);
|
|
// }
|
|
}
|
|
|
|
// 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"));
|
|
|
|
// TODO: Requires variadic function support.
|
|
// Cpp.printf("Hello world!\n\0");
|
|
}
|
|
|
|
// 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*.
|
|
// let s: str = "Hello world!\n";
|
|
// Cpp.write(1, Cpp.std.data(s), Cpp.std.size(s));
|
|
}
|
|
|
|
fn HelloIostreams() {
|
|
Cpp.std.cout << "Hello world!\n";
|
|
}
|
|
|
|
fn Run() {
|
|
HelloPutchar();
|
|
HelloStdio();
|
|
HelloWrite();
|
|
HelloIostreams();
|
|
}
|