Recover better from invalid C++ classes. (#5992)

When importing a class definition, don't ask for the class layout if the
definition is invalid. Avoids an assertion failure in Clang.

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
This commit is contained in:
Richard Smith
2025-09-02 19:32:35 +00:00
committed by GitHub
co-authored by Dana Jansens
parent 00d0eb85e2
commit 4483d1e5a7
3 changed files with 63 additions and 0 deletions
+5
View File
@@ -825,6 +825,11 @@ static auto ImportClassObjectRepr(Context& context, SemIR::ClassId class_id,
SemIR::TypeInstId class_type_inst_id,
const clang::CXXRecordDecl* clang_def)
-> SemIR::TypeInstId {
if (clang_def->isInvalidDecl()) {
// Clang already diagnosed this error.
return SemIR::ErrorInst::TypeInstId;
}
// For now, if the class is empty, produce an empty struct as the object
// representation. This allows our tests to continue to pass while we don't
// properly support initializing imported C++ classes.