Skip to content

Commit b27844e

Browse files
committed
c++, contracts: Fix up constification of out-of-class defs.
Add a missing const-ification case. Signed-off-by: Iain Sandoe <[email protected]>
1 parent 5c59f09 commit b27844e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

gcc/cp/parser.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31511,6 +31511,12 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
3151131511
should_constify = false;
3151231512
flag_contracts_nonattr_noconst = !should_constify;
3151331513

31514+
/* If we have a current class object, see if we need to consider
31515+
it const when processing the contract condition. */
31516+
tree current_class_ref_copy = current_class_ref;
31517+
if (flag_contracts_nonattr && should_constify && current_class_ref_copy)
31518+
current_class_ref = view_as_const (current_class_ref_copy);
31519+
3151431520
/* Parse the condition, ensuring that parameters or the return variable
3151531521
aren't flagged for use outside the body of a function. */
3151631522
++processing_contract_condition;
@@ -31519,6 +31525,8 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute,
3151931525
cp_expr condition = cp_parser_conditional_expression (parser);
3152031526
if (postcondition_p)
3152131527
--processing_contract_postcondition;
31528+
/* Revert (any) constification of the current class object. */
31529+
current_class_ref = current_class_ref_copy;
3152231530
flag_contracts_nonattr_noconst = old_flag_contracts_nonattr_noconst;
3152331531
--processing_contract_condition;
3152431532

0 commit comments

Comments
 (0)