File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -873,8 +873,13 @@ void c_typecheck_baset::typecheck_compound_body(
873
873
{
874
874
struct_union_typet::componentt new_component;
875
875
876
- new_component.add_source_location ()=
877
- declarator.source_location ();
876
+ // There may be a declarator, which we use as location for
877
+ // the component. Otherwise, use location of the declaration.
878
+ const source_locationt source_location =
879
+ declarator.get_name ().empty () ? declaration.source_location ()
880
+ : declarator.source_location ();
881
+
882
+ new_component.add_source_location () = source_location;
878
883
new_component.set (ID_name, declarator.get_base_name ());
879
884
new_component.set (ID_pretty_name, declarator.get_base_name ());
880
885
new_component.type ()=declaration.full_type (declarator);
@@ -885,7 +890,7 @@ void c_typecheck_baset::typecheck_compound_body(
885
890
(new_component.type ().id ()!=ID_array ||
886
891
!to_array_type (new_component.type ()).is_incomplete ()))
887
892
{
888
- error ().source_location =new_component. type (). source_location () ;
893
+ error ().source_location = source_location;
889
894
error () << " incomplete type not permitted here" << eom;
890
895
throw 0 ;
891
896
}
Original file line number Diff line number Diff line change @@ -1634,7 +1634,8 @@ member_declaration:
1634
1634
| member_default_declaring_list ' ;'
1635
1635
| ' ;' /* empty declaration */
1636
1636
{
1637
- init ($$, ID_declaration);
1637
+ $$ =$1 ; // the ';' becomes the location of the declaration
1638
+ stack ($$).id(ID_declaration);
1638
1639
}
1639
1640
| static_assert_declaration ' ;'
1640
1641
;
@@ -1651,6 +1652,7 @@ member_default_declaring_list:
1651
1652
1652
1653
init ($$, ID_declaration);
1653
1654
to_ansi_c_declaration (stack($$)).set_is_member(true );
1655
+ stack ($$).add_source_location()=stack($2 ).source_location();
1654
1656
stack ($$).type().swap(stack($2 ));
1655
1657
PARSER.add_declarator(stack($$ ), stack($3 ));
1656
1658
}
@@ -1686,6 +1688,7 @@ member_declaring_list:
1686
1688
1687
1689
init ($$, ID_declaration);
1688
1690
to_ansi_c_declaration (stack($$)).set_is_member(true );
1691
+ stack ($$).add_source_location()=stack($2 ).source_location();
1689
1692
stack ($$).type().swap(stack($2 ));
1690
1693
PARSER.add_declarator(stack($$ ), stack($3 ));
1691
1694
}
You can’t perform that action at this time.
0 commit comments