@@ -13120,16 +13120,12 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
1312013120 0);
1312113121
1312213122 /* Do we have an override for const-ification? */
13123- bool old_flag_contracts_nonattr_noconst
13124- = flag_contracts_nonattr_noconst;
13125-
1312613123 bool should_constify = !flag_contracts_nonattr_noconst;
1312713124 if (!modifier.error_p
1312813125 && (modifier.mutable_p
1312913126 || (flag_contracts_nonattr_const_keyword
1313013127 && !modifier.const_p)))
1313113128 should_constify = false;
13132- flag_contracts_nonattr_noconst = !should_constify;
1313313129
1313413130 /* If we have a current class object, see if we need to consider
1313513131 it const when processing the contract condition. */
@@ -13138,28 +13134,30 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
1313813134 current_class_ref = view_as_const (current_class_ref_copy);
1313913135
1314013136 /* Parse the condition. */
13137+ tree contract = error_mark_node;
1314113138 begin_scope (sk_contract, current_function_decl);
13142- ++processing_contract_condition;
13139+ bool old_pc = processing_postcondition;
13140+ bool old_const = should_constify_contract;
1314313141 processing_postcondition = false;
1314413142 should_constify_contract = should_constify;
1314513143 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;
1314713152 pop_bindings_and_leave_scope ();
1314813153
1314913154 /* Revert (any) constification of the current class object. */
1315013155 current_class_ref = current_class_ref_copy;
1315113156
13152- flag_contracts_nonattr_noconst
13153- = old_flag_contracts_nonattr_noconst;
13154-
1315513157 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+
1316013159 if (contract != error_mark_node)
1316113160 set_contract_const (contract, should_constify);
13162-
1316313161 std_attrs = finish_contract_attribute (cont_assert, contract);
1316413162
1316513163 /* 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,
3137631374 /* Enable location wrappers when parsing contracts. */
3137731375 auto suppression = make_temp_override (suppress_location_wrappers, 0);
3137831376
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-
3138331377 /* If we have a current class object, see if we need to consider
3138431378 it const when processing the contract condition. */
3138531379 tree current_class_ref_copy = current_class_ref;
@@ -31389,31 +31383,30 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
3138931383 /* Parse the condition, ensuring that parameters or the return variable
3139031384 aren't flagged for use outside the body of a function. */
3139131385 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;
3139531390 tree result = NULL_TREE;
3139631391 if (identifier)
3139731392 {
3139831393 /* Build a fake variable for the result identifier. */
3139931394 result = make_postcondition_variable (identifier);
3140031395 ++processing_template_decl;
3140131396 }
31402- processing_postcondition = postcondition_p;
31403- should_constify_contract = should_constify;
3140431397 cp_expr condition = cp_parser_conditional_expression (parser);
3140531398 /* Build the contract. */
3140631399 contract = grok_contract (attribute, mode, result, condition, loc);
3140731400 if (identifier)
3140831401 --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);
3141231406 pop_bindings_and_leave_scope ();
3141331407
3141431408 /* Revert (any) constification of the current class object. */
3141531409 current_class_ref = current_class_ref_copy;
31416- flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
3141731410
3141831411 /* For natural syntax, we eat the parens here. For the attribute
3141931412 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,
3149831491 cp_token_cache *tokens = DEFPARSE_TOKENS (condition);
3149931492 cp_parser_push_lexer_for_tokens (parser, tokens);
3150031493
31501- bool old_flag_contracts_nonattr_noconst = flag_contracts_nonattr_noconst;
3150231494 bool should_constify = get_contract_const (contract);
3150331495 /* If we have a current class object, see if we need to consider
3150431496 it const when processing the contract condition. */
@@ -31509,9 +31501,10 @@ void cp_parser_late_contract_condition (cp_parser *parser,
3150931501 /* Parse the condition, ensuring that parameters or the return variable
3151031502 aren't flagged for use outside the body of a function. */
3151131503 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;
3151531508 /* Build a fake variable for the result identifier. */
3151631509 tree result = NULL_TREE;
3151731510 if (identifier)
@@ -31523,15 +31516,14 @@ void cp_parser_late_contract_condition (cp_parser *parser,
3152331516 /* Commit to changes. */
3152431517 update_late_contract (contract, result, condition);
3152531518 /* Leave our temporary scope for the postcondition result. */
31526- if (result )
31519+ if (identifier )
3152731520 --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);
3153131525 pop_bindings_and_leave_scope ();
3153231526
31533- flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
31534-
3153531527 if (cp_lexer_next_token_is_not (parser->lexer, CPP_EOF))
3153631528 error_at (input_location, "expected conditional-expression");
3153731529
0 commit comments