@@ -13219,16 +13219,12 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
13219
13219
0);
13220
13220
13221
13221
/* Do we have an override for const-ification? */
13222
- bool old_flag_contracts_nonattr_noconst
13223
- = flag_contracts_nonattr_noconst;
13224
-
13225
13222
bool should_constify = !flag_contracts_nonattr_noconst;
13226
13223
if (!modifier.error_p
13227
13224
&& (modifier.mutable_p
13228
13225
|| (flag_contracts_nonattr_const_keyword
13229
13226
&& !modifier.const_p)))
13230
13227
should_constify = false;
13231
- flag_contracts_nonattr_noconst = !should_constify;
13232
13228
13233
13229
/* If we have a current class object, see if we need to consider
13234
13230
it const when processing the contract condition. */
@@ -13237,28 +13233,30 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
13237
13233
current_class_ref = view_as_const (current_class_ref_copy);
13238
13234
13239
13235
/* Parse the condition. */
13236
+ tree contract = error_mark_node;
13240
13237
begin_scope (sk_contract, current_function_decl);
13241
- ++processing_contract_condition;
13238
+ bool old_pc = processing_postcondition;
13239
+ bool old_const = should_constify_contract;
13242
13240
processing_postcondition = false;
13243
13241
should_constify_contract = should_constify;
13244
13242
cp_expr condition = cp_parser_conditional_expression (parser);
13245
- --processing_contract_condition;
13243
+ gcc_checking_assert (scope_chain && scope_chain->bindings
13244
+ && scope_chain->bindings->kind == sk_contract);
13245
+ /* Build the contract. */
13246
+ contract
13247
+ = grok_contract (cont_assert, /*mode*/NULL_TREE,
13248
+ /*result*/NULL_TREE, condition, loc);
13249
+ processing_postcondition = old_pc;
13250
+ should_constify_contract = old_const;
13246
13251
pop_bindings_and_leave_scope ();
13247
13252
13248
13253
/* Revert (any) constification of the current class object. */
13249
13254
current_class_ref = current_class_ref_copy;
13250
13255
13251
- flag_contracts_nonattr_noconst
13252
- = old_flag_contracts_nonattr_noconst;
13253
-
13254
13256
parens.require_close (parser);
13255
- /* Build the contract. */
13256
- tree contract
13257
- = grok_contract (cont_assert, /*mode*/NULL_TREE,
13258
- /*result*/NULL_TREE, condition, loc);
13257
+
13259
13258
if (contract != error_mark_node)
13260
13259
set_contract_const (contract, should_constify);
13261
-
13262
13260
std_attrs = finish_contract_attribute (cont_assert, contract);
13263
13261
13264
13262
/* If there are errors in the contract, we do not create the
@@ -31507,10 +31505,6 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
31507
31505
/* Enable location wrappers when parsing contracts. */
31508
31506
auto suppression = make_temp_override (suppress_location_wrappers, 0);
31509
31507
31510
- bool old_flag_contracts_nonattr_noconst = flag_contracts_nonattr_noconst;
31511
- /* The should_constify value should account for all the mixed flags. */
31512
- flag_contracts_nonattr_noconst = !should_constify;
31513
-
31514
31508
/* If we have a current class object, see if we need to consider
31515
31509
it const when processing the contract condition. */
31516
31510
tree current_class_ref_copy = current_class_ref;
@@ -31520,31 +31514,30 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
31520
31514
/* Parse the condition, ensuring that parameters or the return variable
31521
31515
aren't flagged for use outside the body of a function. */
31522
31516
begin_scope (sk_contract, current_function_decl);
31523
- ++processing_contract_condition;
31524
- if (postcondition_p)
31525
- ++processing_contract_postcondition;
31517
+ bool old_pc = processing_postcondition;
31518
+ bool old_const = should_constify_contract;
31519
+ processing_postcondition = postcondition_p;
31520
+ should_constify_contract = should_constify;
31526
31521
tree result = NULL_TREE;
31527
31522
if (identifier)
31528
31523
{
31529
31524
/* Build a fake variable for the result identifier. */
31530
31525
result = make_postcondition_variable (identifier);
31531
31526
++processing_template_decl;
31532
31527
}
31533
- processing_postcondition = postcondition_p;
31534
- should_constify_contract = should_constify;
31535
31528
cp_expr condition = cp_parser_conditional_expression (parser);
31536
31529
/* Build the contract. */
31537
31530
contract = grok_contract (attribute, mode, result, condition, loc);
31538
31531
if (identifier)
31539
31532
--processing_template_decl;
31540
- if (postcondition_p)
31541
- --processing_contract_postcondition;
31542
- --processing_contract_condition;
31533
+ processing_postcondition = old_pc;
31534
+ should_constify_contract = old_const;
31535
+ gcc_checking_assert (scope_chain && scope_chain->bindings
31536
+ && scope_chain->bindings->kind == sk_contract);
31543
31537
pop_bindings_and_leave_scope ();
31544
31538
31545
31539
/* Revert (any) constification of the current class object. */
31546
31540
current_class_ref = current_class_ref_copy;
31547
- flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
31548
31541
31549
31542
/* For natural syntax, we eat the parens here. For the attribute
31550
31543
syntax, it will be done one level up, we just need to skip to it. */
@@ -31629,7 +31622,6 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31629
31622
cp_token_cache *tokens = DEFPARSE_TOKENS (condition);
31630
31623
cp_parser_push_lexer_for_tokens (parser, tokens);
31631
31624
31632
- bool old_flag_contracts_nonattr_noconst = flag_contracts_nonattr_noconst;
31633
31625
bool should_constify = get_contract_const (contract);
31634
31626
/* If we have a current class object, see if we need to consider
31635
31627
it const when processing the contract condition. */
@@ -31640,9 +31632,10 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31640
31632
/* Parse the condition, ensuring that parameters or the return variable
31641
31633
aren't flagged for use outside the body of a function. */
31642
31634
begin_scope (sk_contract, fn);
31643
- ++processing_contract_condition;
31644
- if (POSTCONDITION_P (contract))
31645
- ++processing_contract_postcondition;
31635
+ bool old_pc = processing_postcondition;
31636
+ bool old_const = should_constify_contract;
31637
+ processing_postcondition = POSTCONDITION_P (contract);
31638
+ should_constify_contract = should_constify;
31646
31639
/* Build a fake variable for the result identifier. */
31647
31640
tree result = NULL_TREE;
31648
31641
if (identifier)
@@ -31654,15 +31647,14 @@ void cp_parser_late_contract_condition (cp_parser *parser,
31654
31647
/* Commit to changes. */
31655
31648
update_late_contract (contract, result, condition);
31656
31649
/* Leave our temporary scope for the postcondition result. */
31657
- if (result )
31650
+ if (identifier )
31658
31651
--processing_template_decl;
31659
- if (POSTCONDITION_P (contract))
31660
- --processing_contract_postcondition;
31661
- --processing_contract_condition;
31652
+ processing_postcondition = old_pc;
31653
+ should_constify_contract = old_const;
31654
+ gcc_checking_assert (scope_chain && scope_chain->bindings
31655
+ && scope_chain->bindings->kind == sk_contract);
31662
31656
pop_bindings_and_leave_scope ();
31663
31657
31664
- flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
31665
-
31666
31658
if (cp_lexer_next_token_is_not (parser->lexer, CPP_EOF))
31667
31659
error_at (input_location, "expected conditional-expression");
31668
31660
0 commit comments