Skip to content

Commit 47a2e34

Browse files
author
Daniel Kroening
committed
two additional checks on array subtypes
1 parent b38b671 commit 47a2e34

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/ansi-c/c_typecheck_type.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,32 @@ void c_typecheck_baset::typecheck_array_type(array_typet &type)
489489
typecheck_type(type.subtype());
490490

491491
// we don't allow void as subtype
492-
if(follow(type.subtype()).id()==ID_empty)
492+
if(type.subtype().id()==ID_empty)
493493
{
494494
error().source_location=type.source_location();
495495
error() << "array of voids" << eom;
496496
throw 0;
497497
}
498498

499+
// we don't allow incomplete structs or unions as subtype
500+
if(follow(type.subtype()).id()==ID_incomplete_struct ||
501+
follow(type.subtype()).id()==ID_incomplete_union)
502+
{
503+
// ISO/IEC 9899 6.7.5.2
504+
error().source_location=type.source_location();
505+
error() << "array has incomplete element type" << eom;
506+
throw 0;
507+
}
508+
509+
// we don't allow functions as subtype
510+
if(type.subtype().id()==ID_code)
511+
{
512+
// ISO/IEC 9899 6.7.5.2
513+
error().source_location=type.source_location();
514+
error() << "array of function element type" << eom;
515+
throw 0;
516+
}
517+
499518
// check size, if any
500519

501520
if(size.is_not_nil())

0 commit comments

Comments
 (0)