@@ -1019,15 +1019,21 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol)
10191019 throw 0 ;
10201020 }
10211021
1022- typet final_type=follow (declaration.type ());
1023-
10241022 // anonymous member?
1025- if (declaration.declarators ().empty () &&
1026- final_type.get_bool (ID_C_is_anonymous))
1023+ if (
1024+ declaration.declarators ().empty () &&
1025+ ((declaration.type ().id () == ID_struct_tag &&
1026+ follow_tag (to_struct_tag_type (declaration.type ()))
1027+ .get_bool (ID_C_is_anonymous)) ||
1028+ (declaration.type ().id () == ID_union_tag &&
1029+ follow_tag (to_union_tag_type (declaration.type ()))
1030+ .get_bool (ID_C_is_anonymous)) ||
1031+ declaration.type ().get_bool (ID_C_is_anonymous)))
10271032 {
10281033 // we only allow this on struct/union types
1029- if (final_type.id ()!=ID_union &&
1030- final_type.id ()!=ID_struct)
1034+ if (
1035+ declaration.type ().id () != ID_union_tag &&
1036+ declaration.type ().id () != ID_struct_tag)
10311037 {
10321038 error ().source_location =declaration.type ().source_location ();
10331039 error () << " member declaration does not declare anything"
@@ -1423,8 +1429,14 @@ void cpp_typecheckt::convert_anon_struct_union_member(
14231429 const irep_idt &access,
14241430 struct_typet::componentst &components)
14251431{
1432+ const struct_union_typet &final_type =
1433+ declaration.type ().id () == ID_struct_tag
1434+ ? static_cast <const struct_union_typet &>(
1435+ follow_tag (to_struct_tag_type (declaration.type ())))
1436+ : static_cast <const struct_union_typet &>(
1437+ follow_tag (to_union_tag_type (declaration.type ())));
14261438 symbolt &struct_union_symbol =
1427- symbol_table.get_writeable_ref (follow (declaration. type ()) .get (ID_name));
1439+ symbol_table.get_writeable_ref (final_type .get (ID_name));
14281440
14291441 if (declaration.storage_spec ().is_static () ||
14301442 declaration.storage_spec ().is_mutable ())
@@ -1477,13 +1489,15 @@ bool cpp_typecheckt::get_component(
14771489 const irep_idt &component_name,
14781490 exprt &member)
14791491{
1480- const typet &followed_type=follow (object.type ());
1481-
14821492 PRECONDITION (
1483- followed_type. id () == ID_struct || followed_type. id () == ID_union );
1493+ object. type (). id () == ID_struct_tag || object. type (). id () == ID_union_tag );
14841494
1485- struct_union_typet final_type=
1486- to_struct_union_type (followed_type);
1495+ struct_union_typet final_type =
1496+ object.type ().id () == ID_struct_tag
1497+ ? static_cast <const struct_union_typet &>(
1498+ follow_tag (to_struct_tag_type (object.type ())))
1499+ : static_cast <const struct_union_typet &>(
1500+ follow_tag (to_union_tag_type (object.type ())));
14871501
14881502 const struct_union_typet::componentst &components=
14891503 final_type.components ();
@@ -1529,14 +1543,22 @@ bool cpp_typecheckt::get_component(
15291543
15301544 return true ; // component found
15311545 }
1532- else if (follow (component.type ()).find (ID_C_unnamed_object).is_not_nil ())
1546+ else if (
1547+ (component.type ().id () == ID_struct_tag &&
1548+ follow_tag (to_struct_tag_type (component.type ()))
1549+ .find (ID_C_unnamed_object)
1550+ .is_not_nil ()) ||
1551+ (component.type ().id () == ID_union_tag &&
1552+ follow_tag (to_union_tag_type (component.type ()))
1553+ .find (ID_C_unnamed_object)
1554+ .is_not_nil ()) ||
1555+ component.type ().find (ID_C_unnamed_object).is_not_nil ())
15331556 {
15341557 // could be anonymous union or struct
15351558
1536- const typet &component_type=follow (component.type ());
1537-
1538- if (component_type.id ()==ID_union ||
1539- component_type.id ()==ID_struct)
1559+ if (
1560+ component.type ().id () == ID_union_tag ||
1561+ component.type ().id () == ID_struct_tag)
15401562 {
15411563 // recursive call!
15421564 if (get_component (source_location, tmp, component_name, member))
@@ -1680,18 +1702,17 @@ bool cpp_typecheckt::subtype_typecast(
16801702
16811703void cpp_typecheckt::make_ptr_typecast (
16821704 exprt &expr,
1683- const typet &dest_type)
1705+ const pointer_typet &dest_type)
16841706{
16851707 typet src_type=expr.type ();
16861708
16871709 PRECONDITION (src_type.id () == ID_pointer);
1688- PRECONDITION (dest_type.id () == ID_pointer);
16891710
1690- const struct_typet &src_struct = to_struct_type (
1691- static_cast < const typet &>( follow (to_pointer_type (src_type).base_type () )));
1711+ const struct_typet &src_struct =
1712+ follow_tag ( to_struct_tag_type (to_pointer_type (src_type).base_type ()));
16921713
1693- const struct_typet &dest_struct = to_struct_type (
1694- static_cast < const typet &>( follow ( to_pointer_type ( dest_type) .base_type () )));
1714+ const struct_typet &dest_struct =
1715+ follow_tag ( to_struct_tag_type ( dest_type.base_type ()));
16951716
16961717 PRECONDITION (
16971718 subtype_typecast (src_struct, dest_struct) ||
0 commit comments