mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Make C++ types impl Core.Default. (#6962)
C++ classes that are default-constructible now implement `Core.Default` by calling the default constructor.
This commit is contained in:
@@ -8,6 +8,12 @@ package Core library "prelude/parts/default";
|
||||
|
||||
interface DefaultOrUnformed { fn Op() -> Self; }
|
||||
|
||||
interface Default { fn Op() -> Self; }
|
||||
|
||||
final impl forall [T:! Default] T as DefaultOrUnformed {
|
||||
fn Op() -> Self { return T.(Default.Op)(); }
|
||||
}
|
||||
|
||||
// In tests, just allow any type to be default-initialized as a no-op.
|
||||
// TODO: This is a hack to allow existing tests to contiue working.
|
||||
impl forall [T:! type] T as DefaultOrUnformed {
|
||||
|
||||
Reference in New Issue
Block a user