Skip to content

Commit 946abb8

Browse files
authored
Merge pull request #2840 from diffblue/ansi-c-array-subtype-checks
two additional checks on array subtypes
2 parents d733fe3 + 99f0aa8 commit 946abb8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/ansi-c/c_typecheck_type.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,33 @@ 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(
501+
follow(type.subtype()).id() == ID_incomplete_struct ||
502+
follow(type.subtype()).id() == ID_incomplete_union)
503+
{
504+
// ISO/IEC 9899 6.7.5.2
505+
error().source_location = type.source_location();
506+
error() << "array has incomplete element type" << eom;
507+
throw 0;
508+
}
509+
510+
// we don't allow functions as subtype
511+
if(type.subtype().id() == ID_code)
512+
{
513+
// ISO/IEC 9899 6.7.5.2
514+
error().source_location = type.source_location();
515+
error() << "array of function element type" << eom;
516+
throw 0;
517+
}
518+
499519
// check size, if any
500520

501521
if(size.is_not_nil())

0 commit comments

Comments
 (0)