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 @@ -874,8 +874,13 @@ void c_typecheck_baset::typecheck_compound_body(
874
874
{
875
875
struct_union_typet::componentt new_component;
876
876
877
- new_component.add_source_location ()=
878
- declarator.source_location ();
877
+ // There may be a declarator, which we use as location for
878
+ // the component. Otherwise, use location of the declaration.
879
+ const source_locationt source_location =
880
+ declarator.get_name ().empty () ? declaration.source_location ()
881
+ : declarator.source_location ();
882
+
883
+ new_component.add_source_location () = source_location;
879
884
new_component.set (ID_name, declarator.get_base_name ());
880
885
new_component.set (ID_pretty_name, declarator.get_base_name ());
881
886
new_component.type ()=declaration.full_type (declarator);
@@ -886,7 +891,7 @@ void c_typecheck_baset::typecheck_compound_body(
886
891
(new_component.type ().id ()!=ID_array ||
887
892
!to_array_type (new_component.type ()).is_incomplete ()))
888
893
{
889
- error ().source_location =new_component. type (). source_location () ;
894
+ error ().source_location = source_location;
890
895
error () << " incomplete type not permitted here" << eom;
891
896
throw 0 ;
892
897
}
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