mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 18:51:09 +01:00
Export Carbon classes as base / final / abstract. (#7191)
* For Carbon `base class C`, export as a regular C++ class. * For Carbon `class C`, export with the C++ `final` keyword attribute. * For Carbon `abstract C`, mark the destructor as pure virtual in cases where no member function is abstract, or emit an error if the destructor is not virtual. To support the final point, mark the destructor of an exported class as virtual if it overrides a virtual destructor from the base class. In passing, fix a crash exporting fields if the class has an invalid base type.
This commit is contained in:
@@ -1801,9 +1801,16 @@ static auto ImportFunction(Context& context, SemIR::LocId loc_id,
|
||||
}
|
||||
if (virtual_modifier != SemIR::Function::VirtualModifier::None) {
|
||||
// TODO: Add support for Microsoft/non-Itanium vtables.
|
||||
clang::GlobalDecl decl;
|
||||
if (auto* dtor_decl = dyn_cast<clang::CXXDestructorDecl>(method_decl)) {
|
||||
// TODO: Do we want the index of the complete or base destructor?
|
||||
decl = clang::GlobalDecl(dtor_decl, clang::Dtor_Complete);
|
||||
} else {
|
||||
decl = clang::GlobalDecl(method_decl);
|
||||
}
|
||||
virtual_index = dyn_cast<clang::ItaniumVTableContext>(
|
||||
context.ast_context().getVTableContext())
|
||||
->getMethodVTableIndex(method_decl);
|
||||
->getMethodVTableIndex(decl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user