@@ -13120,16 +13120,12 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
13120
13120
0);
13121
13121
13122
13122
/* Do we have an override for const-ification? */
13123
- bool old_flag_contracts_nonattr_noconst
13124
- = flag_contracts_nonattr_noconst;
13125
-
13126
13123
bool should_constify = !flag_contracts_nonattr_noconst;
13127
13124
if (!modifier.error_p
13128
13125
&& (modifier.mutable_p
13129
13126
|| (flag_contracts_nonattr_const_keyword
13130
13127
&& !modifier.const_p)))
13131
13128
should_constify = false;
13132
- flag_contracts_nonattr_noconst = !should_constify;
13133
13129
13134
13130
/* If we have a current class object, see if we need to consider
13135
13131
it const when processing the contract condition. */
@@ -13138,28 +13134,30 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
13138
13134
current_class_ref = view_as_const (current_class_ref_copy);
13139
13135
13140
13136
/* Parse the condition. */
13137
+ tree contract = error_mark_node;
13141
13138
begin_scope (sk_contract, current_function_decl);
13142
- ++processing_contract_condition;
13139
+ bool old_pc = processing_postcondition;
13140
+ bool old_const = should_constify_contract;
13143
13141
processing_postcondition = false;
13144
13142
should_constify_contract = should_constify;
13145
13143
cp_expr condition = cp_parser_conditional_expression (parser);
13146
- --processing_contract_condition;
13144
+ gcc_checking_assert (scope_chain && scope_chain->bindings
13145
+ && scope_chain->bindings->kind == sk_contract);
13146
+ /* Build the contract. */
13147
+ contract
13148
+ = grok_contract (cont_assert, /*mode*/NULL_TREE,
13149
+ /*result*/NULL_TREE, condition, loc);
13150
+ processing_postcondition = old_pc;
13151
+ should_constify_contract = old_const;
13147
13152
pop_bindings_and_leave_scope ();
13148
13153
13149
13154
/* Revert (any) constification of the current class object. */
13150
13155
current_class_ref = current_class_ref_copy;
13151
13156
13152
- flag_contracts_nonattr_noconst
13153
- = old_flag_contracts_nonattr_noconst;
13154
-
13155
13157
parens.require_close (parser);
13156
- /* Build the contract. */
13157
- tree contract
13158
- = grok_contract (cont_assert, /*mode*/NULL_TREE,
13159
- /*result*/NULL_TREE, condition, loc);
13158
+
13160
13159
if (contract != error_mark_node)
13161
13160
set_contract_const (contract, should_constify);
13162
-
13163
13161
std_attrs = finish_contract_attribute (cont_assert, contract);
13164
13162
13165
13163
/* If there are errors in the contract, we do not create the
@@ -31376,10 +31374,6 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
31376
31374
/* Enable location wrappers when parsing contracts. */
31377
31375
auto suppression = make_temp_override (suppress_location_wrappers, 0);
31378
31376
31379
- bool old_flag_contracts_nonattr_noconst = flag_contracts_nonattr_noconst;
31380
- /* The should_constify value should account for all the mixed flags. */
31381
- flag_contracts_nonattr_noconst = !should_constify;
31382
-
31383
31377
/* If we have a current class object, see if we need to consider
31384
31378
it const when processing the contract condition. */
31385
31379
tree current_class_ref_copy = current_class_ref;
@@ -31389,31 +31383,30 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
31389
31383
/* Parse the condition, ensuring that parameters or the return variable
31390
31384
aren't flagged for use outside the body of a function. */
31391
31385
begin_scope (sk_contract, current_function_decl);
31392
- ++processing_contract_condition;
31393
- if (postcondition_p)
31394
- ++processing_contract_postcondition;
31386
+ bool old_pc = processing_postcondition;
31387
+ bool old_const = should_constify_contract;
31388
+ processing_postcondition = postcondition_p;
31389
+ should_constify_contract = should_constify;
31395
31390
tree result = NULL_TREE;
31396
31391
if (identifier)
31397
31392
{
31398
31393
/* Build a fake variable for the result identifier. */
31399
31394
result = make_postcondition_variable (identifier);
31400
31395
++processing_template_decl;
31401
31396
}
31402
- processing_postcondition = postcondition_p;
31403
- should_constify_contract = should_constify;
31404
31397
cp_expr condition = cp_parser_conditional_expression (parser);
31405
31398
/* Build the contract. */
31406
31399
contract = grok_contract (attribute, mode, result, condition, loc);
31407
31400
if (identifier)
31408
31401
--processing_template_decl;
31409
- if (postcondition_p)
31410
- --processing_contract_postcondition;
31411
- --processing_contract_condition;
31402
+ processing_postcondition = old_pc;
31403
+ should_constify_contract = old_const;
31404
+ gcc_checking_assert (scope_chain && scope_chain->bindings
31405
+ && scope_chain->bindings->kind == sk_contract);
31412
31406
pop_bindings_and_leave_scope ();
31413
31407
31414
31408
/* Revert (any) constification of the current class object. */
31415
31409
current_class_ref = current_class_ref_copy;
31416
- flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
31417
31410
31418
31411
/* For natural syntax, we eat the parens here. For the attribute
31419
31412
syntax, it will be done one level up, we just need to skip to it. */
@@ -31498,7 +31491,6 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31498
31491
cp_token_cache *tokens = DEFPARSE_TOKENS (condition);
31499
31492
cp_parser_push_lexer_for_tokens (parser, tokens);
31500
31493
31501
- bool old_flag_contracts_nonattr_noconst = flag_contracts_nonattr_noconst;
31502
31494
bool should_constify = get_contract_const (contract);
31503
31495
/* If we have a current class object, see if we need to consider
31504
31496
it const when processing the contract condition. */
@@ -31509,9 +31501,10 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31509
31501
/* Parse the condition, ensuring that parameters or the return variable
31510
31502
aren't flagged for use outside the body of a function. */
31511
31503
begin_scope (sk_contract, fn);
31512
- ++processing_contract_condition;
31513
- if (POSTCONDITION_P (contract))
31514
- ++processing_contract_postcondition;
31504
+ bool old_pc = processing_postcondition;
31505
+ bool old_const = should_constify_contract;
31506
+ processing_postcondition = POSTCONDITION_P (contract);
31507
+ should_constify_contract = should_constify;
31515
31508
/* Build a fake variable for the result identifier. */
31516
31509
tree result = NULL_TREE;
31517
31510
if (identifier)
@@ -31523,15 +31516,14 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31523
31516
/* Commit to changes. */
31524
31517
update_late_contract (contract, result, condition);
31525
31518
/* Leave our temporary scope for the postcondition result. */
31526
- if (result )
31519
+ if (identifier )
31527
31520
--processing_template_decl;
31528
- if (POSTCONDITION_P (contract))
31529
- --processing_contract_postcondition;
31530
- --processing_contract_condition;
31521
+ processing_postcondition = old_pc;
31522
+ should_constify_contract = old_const;
31523
+ gcc_checking_assert (scope_chain && scope_chain->bindings
31524
+ && scope_chain->bindings->kind == sk_contract);
31531
31525
pop_bindings_and_leave_scope ();
31532
31526
31533
- flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
31534
-
31535
31527
if (cp_lexer_next_token_is_not (parser->lexer, CPP_EOF))
31536
31528
error_at (input_location, "expected conditional-expression");
31537
31529
0 commit comments