Interop support for `std::getline`
Author: zygoloidCreated May 25, 2026Updated Aug 24, 2026
Labelsinactive
Meta-bug for various issues calling std::getline via C++ interop. Testcases of increasing complexity:
import Cpp library "<fstream>";
fn F(ref f: Cpp.std.istream, ref s: Cpp.std.string) -> bool {
return not Cpp.std.getline(ref f, ref s).fail();
}
fn G(ref f: Cpp.std.istream, ref s: Cpp.std.string) -> bool {
return Cpp.std.getline(ref f, ref s) as bool;
}
fn H(ref f: Cpp.std.ifstream, ref s: Cpp.std.string) -> bool {
return Cpp.std.getline(ref f, ref s) as bool;
}
fn I(ref f: Cpp.std.ifstream, ref s: Cpp.std.string) {
if (Cpp.std.getline(ref f, ref s)) {}
}These should all work, but all fail for various different reasons. Ultimately, the goal is to be able to call getline as in I. The distinct bugs I've been able to tease apart are:
- In the first and second call, we attempt to copy the
istream(to callgetline) and its base classbasic_ios(to callfail). This is likely due tobasic_iosbeing a virtual base class. - In the third call we additionally reject the
ref fargument, claiming both thatrefis present and not permitted and that it is absent and required. (#7258) - In the fourth call, we additionally fail to find the
istream->boolexplicit conversion. Should explicit conversions toboolbe used byiflike they are in C++? - If the
operator boolwere non-explicitand there were no virtual inheritance, we would crash when lowering theoperator boolcall.
Source: carbon-language/carbon-lang