mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
When performing an implicit conversion to or from a C++ class type, look for a C++ implicit conversion, and if that conversion involves a function call (to a constructor or conversion function), call that function to perform the conversion. Note that this is just a first pass at supporting implicit conversions. There are a lot of other things that can happen in a C++ implicit conversion, such as aggregate initialization or `std::initializer_list` initialization that aren't handled here. In addition, we intentionally leave all standard conversions to Carbon to perform, so that we will reject conversions such as `i32 -> unsigned` that C++ would select but Carbon considers to be invalid. Also support `as` conversions. These are treated analogously, but perform direct-initialization instead of copy-initialization, so they also find `explicit` constructors and conversion functions. In order to give good diagnostics, also track the original C++ source location for imported C++ functions on the imported version of the function. Assisted-by: Gemini 3 Pro via Antigravity