@@ -3314,8 +3314,8 @@ void
3314
3314
p2900_duplicate_contracts (tree newdecl, tree olddecl)
3315
3315
{
3316
3316
/* Aggregate the contracts and strip them from the input decls. */
3317
- tree new_contracts = extract_contract_attributes (newdecl);
3318
- tree old_contracts = extract_contract_attributes (olddecl);
3317
+ tree new_contracts = DECL_CONTRACTS (newdecl);
3318
+ tree old_contracts = DECL_CONTRACTS (olddecl);
3319
3319
3320
3320
if (!old_contracts && !new_contracts)
3321
3321
return ;
@@ -3328,9 +3328,9 @@ p2900_duplicate_contracts (tree newdecl, tree olddecl)
3328
3328
also be needed when we process deferred contracts. */
3329
3329
bool existed = false ;
3330
3330
contract_redecl& rd = redeclared_contracts.get_or_insert (olddecl, &existed);
3331
- if (!existed)
3331
+ if (!existed && ! contract_any_deferred_p (old_contracts) )
3332
3332
{
3333
- rd.original_contracts = old_contracts ;
3333
+ rd.original_contracts = copy_contracts (olddecl) ;
3334
3334
location_t cont_end = old_loc;
3335
3335
if (old_contracts)
3336
3336
cont_end = get_contract_end_loc (old_contracts);
@@ -3351,20 +3351,13 @@ p2900_duplicate_contracts (tree newdecl, tree olddecl)
3351
3351
return ;
3352
3352
}
3353
3353
3354
- /* If have now parsed deferred contracts for the 'first' decl, update the
3355
- saved record. */
3356
- if (rd.original_contracts
3357
- && contract_any_deferred_p (rd.original_contracts )
3358
- && old_contracts
3359
- && !contract_any_deferred_p (old_contracts))
3360
- rd.original_contracts = old_contracts;
3361
-
3362
3354
if (old_contracts && !new_contracts)
3363
3355
/* We allow re-declarations to omit contracts declared on the initial decl.
3364
3356
In fact, this is required if the conditions contain lambdas. Check if
3365
3357
all the parameters are correctly const qualified. */
3366
3358
check_param_in_redecl (olddecl, newdecl);
3367
- else if (contract_any_deferred_p (new_contracts))
3359
+ else if (contract_any_deferred_p (new_contracts)
3360
+ || contract_any_deferred_p (old_contracts))
3368
3361
/* TODO: stash these and figure out how to process them later. */
3369
3362
;
3370
3363
else
@@ -3377,10 +3370,12 @@ p2900_duplicate_contracts (tree newdecl, tree olddecl)
3377
3370
}
3378
3371
3379
3372
/* We have maybe issued a diagnostic - but because the caller will smash the
3380
- attributes on the old decl with those on the new, we need to copy the old
3381
- ones onto the new. */
3373
+ attributes on the old decl with those on the new, we need to remove the
3374
+ contracts from the old decl and move the old contracts onto the new decl. */
3375
+ remove_contract_attributes (newdecl);
3382
3376
DECL_ATTRIBUTES (newdecl)
3383
- = attr_chainon (DECL_ATTRIBUTES (newdecl), old_contracts);
3377
+ = attr_chainon (DECL_ATTRIBUTES (newdecl),
3378
+ extract_contract_attributes (olddecl));
3384
3379
return ;
3385
3380
}
3386
3381
0 commit comments