@@ -31376,15 +31376,6 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
31376
31376
/* Enable location wrappers when parsing contracts. */
31377
31377
auto suppression = make_temp_override (suppress_location_wrappers, 0);
31378
31378
31379
- /* Build a fake variable for the result identifier. */
31380
- tree result = NULL_TREE;
31381
- if (identifier)
31382
- {
31383
- begin_scope (sk_block, NULL_TREE);
31384
- result = make_postcondition_variable (identifier);
31385
- ++processing_template_decl;
31386
- }
31387
-
31388
31379
bool old_flag_contracts_nonattr_noconst = flag_contracts_nonattr_noconst;
31389
31380
/* The should_constify value should account for all the mixed flags. */
31390
31381
flag_contracts_nonattr_noconst = !should_constify;
@@ -31401,13 +31392,25 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
31401
31392
++processing_contract_condition;
31402
31393
if (postcondition_p)
31403
31394
++processing_contract_postcondition;
31395
+ tree result = NULL_TREE;
31396
+ if (identifier)
31397
+ {
31398
+ /* Build a fake variable for the result identifier. */
31399
+ result = make_postcondition_variable (identifier);
31400
+ ++processing_template_decl;
31401
+ }
31404
31402
processing_postcondition = postcondition_p;
31405
31403
should_constify_contract = should_constify;
31406
31404
cp_expr condition = cp_parser_conditional_expression (parser);
31405
+ /* Build the contract. */
31406
+ contract = grok_contract (attribute, mode, result, condition, loc);
31407
+ if (identifier)
31408
+ --processing_template_decl;
31407
31409
if (postcondition_p)
31408
31410
--processing_contract_postcondition;
31409
31411
--processing_contract_condition;
31410
31412
pop_bindings_and_leave_scope ();
31413
+
31411
31414
/* Revert (any) constification of the current class object. */
31412
31415
current_class_ref = current_class_ref_copy;
31413
31416
flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
@@ -31421,15 +31424,6 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
31421
31424
we need to search the condition for errors. */
31422
31425
else if (contains_error_p (condition))
31423
31426
cp_parser_skip_up_to_closing_square_bracket (parser);
31424
-
31425
- /* Build the contract. */
31426
- contract = grok_contract (attribute, mode, result, condition, loc);
31427
- /* Leave our temporary scope for the postcondition result. */
31428
- if (result)
31429
- {
31430
- --processing_template_decl;
31431
- pop_bindings_and_leave_scope ();
31432
- }
31433
31427
}
31434
31428
31435
31429
if (!flag_contracts)
@@ -31463,22 +31457,16 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31463
31457
if (TREE_CODE (contract) == POSTCONDITION_STMT)
31464
31458
identifier = POSTCONDITION_IDENTIFIER (contract);
31465
31459
31466
- /* Build a fake variable for the result identifier. */
31467
- tree result = NULL_TREE;
31460
+ tree type = TREE_TYPE (TREE_TYPE (fn));
31468
31461
if (identifier)
31469
31462
{
31470
31463
/* TODO: Can we guarantee that the identifier has a location? */
31471
31464
location_t loc = cp_expr_location (contract);
31472
- tree type = TREE_TYPE (TREE_TYPE (fn));
31473
31465
if (!check_postcondition_result (fn, type, loc))
31474
31466
{
31475
31467
invalidate_contract (contract);
31476
31468
return;
31477
31469
}
31478
-
31479
- begin_scope (sk_block, NULL_TREE);
31480
- result = make_postcondition_variable (identifier, type);
31481
- ++processing_template_decl;
31482
31470
}
31483
31471
31484
31472
/* In C++20 contracts, 'this' is not allowed in preconditions of
@@ -31524,15 +31512,28 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31524
31512
++processing_contract_condition;
31525
31513
if (POSTCONDITION_P (contract))
31526
31514
++processing_contract_postcondition;
31515
+ /* Build a fake variable for the result identifier. */
31516
+ tree result = NULL_TREE;
31517
+ if (identifier)
31518
+ {
31519
+ result = make_postcondition_variable (identifier, type);
31520
+ ++processing_template_decl;
31521
+ }
31527
31522
condition = cp_parser_conditional_expression (parser);
31523
+ /* Commit to changes. */
31524
+ update_late_contract (contract, result, condition);
31525
+ /* Leave our temporary scope for the postcondition result. */
31526
+ if (result)
31527
+ --processing_template_decl;
31528
31528
if (POSTCONDITION_P (contract))
31529
31529
--processing_contract_postcondition;
31530
31530
--processing_contract_condition;
31531
31531
pop_bindings_and_leave_scope ();
31532
31532
31533
+ flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
31534
+
31533
31535
if (cp_lexer_next_token_is_not (parser->lexer, CPP_EOF))
31534
- error_at (input_location,
31535
- "expected conditional-expression");
31536
+ error_at (input_location, "expected conditional-expression");
31536
31537
31537
31538
/* Revert to the main lexer. */
31538
31539
cp_parser_pop_lexer (parser);
@@ -31543,17 +31544,6 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31543
31544
current_class_ref = saved_ccr;
31544
31545
current_class_ptr = saved_ccp;
31545
31546
contract_class_ptr = saved_contract_ccp;
31546
-
31547
- /* Commit to changes. */
31548
- update_late_contract (contract, result, condition);
31549
- flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
31550
-
31551
- /* Leave our temporary scope for the postcondition result. */
31552
- if (result)
31553
- {
31554
- --processing_template_decl;
31555
- pop_bindings_and_leave_scope ();
31556
- }
31557
31547
}
31558
31548
31559
31549
static contract_modifier
0 commit comments