@@ -290,18 +290,34 @@ auto ClassSymbol::buildClassLayout(Control* control)
290290 alignment = std::max (alignment, baseClassSymbol->alignment ());
291291 }
292292
293+ FieldSymbol* lastField = nullptr ;
294+
293295 for (auto member : scope ()->symbols ()) {
294296 auto field = symbol_cast<FieldSymbol>(member);
295297 if (!field) continue ;
296298 if (field->isStatic ()) continue ;
297299
300+ if (lastField && control->is_unbounded_array (lastField->type ())) {
301+ // If the last field is an unbounded array, we cannot compute the offset
302+ // of the next field, so we report an error.
303+ return std::unexpected (
304+ std::format (" size of incomplete type '{}'" ,
305+ to_string (lastField->type (), lastField->name ())));
306+ }
307+
298308 if (!field->alignment ()) {
299309 return std::unexpected (
300310 std::format (" alignment of incomplete type '{}'" ,
301311 to_string (field->type (), field->name ())));
302312 }
303313
304- auto size = memoryLayout->sizeOf (field->type ());
314+ std::optional<std::size_t > size;
315+
316+ if (control->is_unbounded_array (field->type ())) {
317+ size = 0 ;
318+ } else {
319+ size = memoryLayout->sizeOf (field->type ());
320+ }
305321
306322 if (!size.has_value ()) {
307323 return std::unexpected (
@@ -318,6 +334,8 @@ auto ClassSymbol::buildClassLayout(Control* control)
318334 }
319335
320336 alignment = std::max (alignment, field->alignment ());
337+
338+ lastField = field;
321339 }
322340
323341 offset = align_to (offset, alignment);
0 commit comments