@@ -31546,6 +31546,8 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
31546
31546
DEFPARSE_INSTANTIATIONS (condition) = NULL;
31547
31547
31548
31548
/* And its corresponding contract. */
31549
+ if (identifier)
31550
+ identifier.maybe_add_location_wrapper ();
31549
31551
contract = grok_contract (attribute, mode, identifier, condition, loc);
31550
31552
}
31551
31553
else
@@ -31632,16 +31634,19 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31632
31634
if (TREE_CODE (condition) != DEFERRED_PARSE)
31633
31635
return;
31634
31636
31635
- tree identifier = NULL_TREE;
31637
+ tree r_ident = NULL_TREE;
31636
31638
if (TREE_CODE (contract) == POSTCONDITION_STMT)
31637
- identifier = POSTCONDITION_IDENTIFIER (contract);
31639
+ r_ident = POSTCONDITION_IDENTIFIER (contract);
31638
31640
31639
31641
tree type = TREE_TYPE (TREE_TYPE (fn));
31640
- if (identifier)
31642
+ location_t r_loc = UNKNOWN_LOCATION;
31643
+ if (r_ident)
31641
31644
{
31642
- /* TODO: Can we guarantee that the identifier has a location? */
31643
- location_t loc = cp_expr_location (contract);
31644
- if (!check_postcondition_result (fn, type, loc))
31645
+ r_loc = EXPR_LOCATION (r_ident);
31646
+ r_ident = tree_strip_any_location_wrapper (r_ident);
31647
+ if (r_loc == UNKNOWN_LOCATION)
31648
+ r_loc = cp_expr_location (contract);
31649
+ if (!check_postcondition_result (fn, type, r_loc))
31645
31650
{
31646
31651
invalidate_contract (contract);
31647
31652
return;
@@ -31693,16 +31698,17 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31693
31698
should_constify_contract = should_constify;
31694
31699
/* Build a fake variable for the result identifier. */
31695
31700
tree result = NULL_TREE;
31696
- if (identifier )
31701
+ if (r_ident )
31697
31702
{
31698
- result = make_postcondition_variable (identifier, type);
31703
+ cp_expr result_id (r_ident, r_loc);
31704
+ result = make_postcondition_variable (result_id, type);
31699
31705
++processing_template_decl;
31700
31706
}
31701
31707
cp_expr parsed_condition = cp_parser_conditional_expression (parser);
31702
31708
/* Commit to changes. */
31703
31709
update_late_contract (contract, result, parsed_condition);
31704
31710
/* Leave our temporary scope for the postcondition result. */
31705
- if (identifier )
31711
+ if (r_ident )
31706
31712
--processing_template_decl;
31707
31713
processing_postcondition = old_pc;
31708
31714
should_constify_contract = old_const;
0 commit comments