Partial support for a generic class inheriting from a virtual C++ class (#8007)

This allows a generic class to inherit from a virtual C++ class as long
as the subclass doesn't override any methods. See
toolchain/lower/testdata/interop/cpp/class/import/inherit.carbon for a
working example.

The TODO in `CheckCompleteClassType` is now in
`CarbonExternalASTSource::CompleteType`, and only triggers if virtual
function thunks need to be defined.

A fix in `FileContext::BuildVtable` is also needed: when looking up the
clang decl associated with the vtable, if the class is generic then the
`ClassTemplateSpecializationDecl` associated with the specific is
needed. This required adding `ConstantStore::Get`, since only `const`
access is allowed during lowering.
This commit is contained in:
Nicholas Bishop authored and GitHub committed 2026-10-20 20:43:34 +00:00
1 parent 9799a23262
commit 2e21255855
7 files changed
+267 -16

No files matched your search

+10 -4
View File
@@ -560,10 +560,16 @@ auto CarbonExternalASTSource::CompleteType(clang::TagDecl* tag_decl) -> void {
class_decl->completeDefinition();
// Now the class is complete, we can define the virtual function thunks.
for (auto virtual_fn : pending_virtual_functions) {
DefineExportedVirtualFunction(*context_, virtual_fn.loc_id,
virtual_fn.function_id,
virtual_fn.method_decl);
if (llvm::isa<clang::ClassTemplateSpecializationDecl>(class_decl) &&
!pending_virtual_functions.empty()) {
context_->TODO(class_info.first_decl_id(),
"generic class overriding methods from a C++ virtual class");
} else {
for (auto virtual_fn : pending_virtual_functions) {
DefineExportedVirtualFunction(*context_, virtual_fn.loc_id,
virtual_fn.function_id,
virtual_fn.method_decl);
}
}
}