@@ -31502,6 +31502,8 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
31502
31502
DEFPARSE_INSTANTIATIONS (condition) = NULL;
31503
31503
31504
31504
/* And its corresponding contract. */
31505
+ if (identifier)
31506
+ identifier.maybe_add_location_wrapper ();
31505
31507
contract = grok_contract (attribute, mode, identifier, condition, loc);
31506
31508
}
31507
31509
else
@@ -31588,16 +31590,19 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31588
31590
if (TREE_CODE (condition) != DEFERRED_PARSE)
31589
31591
return;
31590
31592
31591
- tree identifier = NULL_TREE;
31593
+ tree r_ident = NULL_TREE;
31592
31594
if (TREE_CODE (contract) == POSTCONDITION_STMT)
31593
- identifier = POSTCONDITION_IDENTIFIER (contract);
31595
+ r_ident = POSTCONDITION_IDENTIFIER (contract);
31594
31596
31595
31597
tree type = TREE_TYPE (TREE_TYPE (fn));
31596
- if (identifier)
31598
+ location_t r_loc = UNKNOWN_LOCATION;
31599
+ if (r_ident)
31597
31600
{
31598
- /* TODO: Can we guarantee that the identifier has a location? */
31599
- location_t loc = cp_expr_location (contract);
31600
- if (!check_postcondition_result (fn, type, loc))
31601
+ r_loc = EXPR_LOCATION (r_ident);
31602
+ r_ident = tree_strip_any_location_wrapper (r_ident);
31603
+ if (r_loc == UNKNOWN_LOCATION)
31604
+ r_loc = cp_expr_location (contract);
31605
+ if (!check_postcondition_result (fn, type, r_loc))
31601
31606
{
31602
31607
invalidate_contract (contract);
31603
31608
return;
@@ -31649,16 +31654,17 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31649
31654
should_constify_contract = should_constify;
31650
31655
/* Build a fake variable for the result identifier. */
31651
31656
tree result = NULL_TREE;
31652
- if (identifier )
31657
+ if (r_ident )
31653
31658
{
31654
- result = make_postcondition_variable (identifier, type);
31659
+ cp_expr result_id (r_ident, r_loc);
31660
+ result = make_postcondition_variable (result_id, type);
31655
31661
++processing_template_decl;
31656
31662
}
31657
31663
cp_expr parsed_condition = cp_parser_conditional_expression (parser);
31658
31664
/* Commit to changes. */
31659
31665
update_late_contract (contract, result, parsed_condition);
31660
31666
/* Leave our temporary scope for the postcondition result. */
31661
- if (identifier )
31667
+ if (r_ident )
31662
31668
--processing_template_decl;
31663
31669
processing_postcondition = old_pc;
31664
31670
should_constify_contract = old_const;
0 commit comments