mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 10:31:03 +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:
@@ -616,6 +616,15 @@ auto CarbonExternalASTSource::CompleteType(clang::TagDecl* tag_decl) -> void {
|
||||
class_decl->startDefinition();
|
||||
CARBON_CHECK(class_decl->hasDefinition());
|
||||
|
||||
// If the Carbon class is final, mark the C++ class as also being `final`.
|
||||
// Abstract classes are handled when generating the destructor declaration.
|
||||
if (class_info.inheritance_kind == SemIR::Class::InheritanceKind::Final) {
|
||||
// TODO: Find the location of the `final` modifier and use it here.
|
||||
class_decl->addAttr(clang::FinalAttr::Create(
|
||||
context_->ast_context(),
|
||||
GetCppLocation(*context_, SemIR::LocId(class_info.definition_id))));
|
||||
}
|
||||
|
||||
// If the Carbon class has a base class that we can map into C++, add that as
|
||||
// a C++ base class.
|
||||
auto base_type_id =
|
||||
|
||||
Reference in New Issue
Block a user