@@ -31507,15 +31507,6 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
31507
31507
/* Enable location wrappers when parsing contracts. */
31508
31508
auto suppression = make_temp_override (suppress_location_wrappers, 0);
31509
31509
31510
- /* Build a fake variable for the result identifier. */
31511
- tree result = NULL_TREE;
31512
- if (identifier)
31513
- {
31514
- begin_scope (sk_block, NULL_TREE);
31515
- result = make_postcondition_variable (identifier);
31516
- ++processing_template_decl;
31517
- }
31518
-
31519
31510
bool old_flag_contracts_nonattr_noconst = flag_contracts_nonattr_noconst;
31520
31511
/* The should_constify value should account for all the mixed flags. */
31521
31512
flag_contracts_nonattr_noconst = !should_constify;
@@ -31532,13 +31523,25 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
31532
31523
++processing_contract_condition;
31533
31524
if (postcondition_p)
31534
31525
++processing_contract_postcondition;
31526
+ tree result = NULL_TREE;
31527
+ if (identifier)
31528
+ {
31529
+ /* Build a fake variable for the result identifier. */
31530
+ result = make_postcondition_variable (identifier);
31531
+ ++processing_template_decl;
31532
+ }
31535
31533
processing_postcondition = postcondition_p;
31536
31534
should_constify_contract = should_constify;
31537
31535
cp_expr condition = cp_parser_conditional_expression (parser);
31536
+ /* Build the contract. */
31537
+ contract = grok_contract (attribute, mode, result, condition, loc);
31538
+ if (identifier)
31539
+ --processing_template_decl;
31538
31540
if (postcondition_p)
31539
31541
--processing_contract_postcondition;
31540
31542
--processing_contract_condition;
31541
31543
pop_bindings_and_leave_scope ();
31544
+
31542
31545
/* Revert (any) constification of the current class object. */
31543
31546
current_class_ref = current_class_ref_copy;
31544
31547
flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
@@ -31552,15 +31555,6 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
31552
31555
we need to search the condition for errors. */
31553
31556
else if (contains_error_p (condition))
31554
31557
cp_parser_skip_up_to_closing_square_bracket (parser);
31555
-
31556
- /* Build the contract. */
31557
- contract = grok_contract (attribute, mode, result, condition, loc);
31558
- /* Leave our temporary scope for the postcondition result. */
31559
- if (result)
31560
- {
31561
- --processing_template_decl;
31562
- pop_bindings_and_leave_scope ();
31563
- }
31564
31558
}
31565
31559
31566
31560
if (!flag_contracts)
@@ -31594,22 +31588,16 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31594
31588
if (TREE_CODE (contract) == POSTCONDITION_STMT)
31595
31589
identifier = POSTCONDITION_IDENTIFIER (contract);
31596
31590
31597
- /* Build a fake variable for the result identifier. */
31598
- tree result = NULL_TREE;
31591
+ tree type = TREE_TYPE (TREE_TYPE (fn));
31599
31592
if (identifier)
31600
31593
{
31601
31594
/* TODO: Can we guarantee that the identifier has a location? */
31602
31595
location_t loc = cp_expr_location (contract);
31603
- tree type = TREE_TYPE (TREE_TYPE (fn));
31604
31596
if (!check_postcondition_result (fn, type, loc))
31605
31597
{
31606
31598
invalidate_contract (contract);
31607
31599
return;
31608
31600
}
31609
-
31610
- begin_scope (sk_block, NULL_TREE);
31611
- result = make_postcondition_variable (identifier, type);
31612
- ++processing_template_decl;
31613
31601
}
31614
31602
31615
31603
/* In C++20 contracts, 'this' is not allowed in preconditions of
@@ -31655,15 +31643,28 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31655
31643
++processing_contract_condition;
31656
31644
if (POSTCONDITION_P (contract))
31657
31645
++processing_contract_postcondition;
31646
+ /* Build a fake variable for the result identifier. */
31647
+ tree result = NULL_TREE;
31648
+ if (identifier)
31649
+ {
31650
+ result = make_postcondition_variable (identifier, type);
31651
+ ++processing_template_decl;
31652
+ }
31658
31653
condition = cp_parser_conditional_expression (parser);
31654
+ /* Commit to changes. */
31655
+ update_late_contract (contract, result, condition);
31656
+ /* Leave our temporary scope for the postcondition result. */
31657
+ if (result)
31658
+ --processing_template_decl;
31659
31659
if (POSTCONDITION_P (contract))
31660
31660
--processing_contract_postcondition;
31661
31661
--processing_contract_condition;
31662
31662
pop_bindings_and_leave_scope ();
31663
31663
31664
+ flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
31665
+
31664
31666
if (cp_lexer_next_token_is_not (parser->lexer, CPP_EOF))
31665
- error_at (input_location,
31666
- "expected conditional-expression");
31667
+ error_at (input_location, "expected conditional-expression");
31667
31668
31668
31669
/* Revert to the main lexer. */
31669
31670
cp_parser_pop_lexer (parser);
@@ -31674,17 +31675,6 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31674
31675
current_class_ref = saved_ccr;
31675
31676
current_class_ptr = saved_ccp;
31676
31677
contract_class_ptr = saved_contract_ccp;
31677
-
31678
- /* Commit to changes. */
31679
- update_late_contract (contract, result, condition);
31680
- flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
31681
-
31682
- /* Leave our temporary scope for the postcondition result. */
31683
- if (result)
31684
- {
31685
- --processing_template_decl;
31686
- pop_bindings_and_leave_scope ();
31687
- }
31688
31678
}
31689
31679
31690
31680
static contract_modifier
0 commit comments