Commit 13e1fc2
c++, contracts: implicit capture in lambda contract [PR124648]
We were currently accepting invalid code by allowing contract assertions
to trigger implicit lambda captures contrary to:
[expr.prim.lambda.closure] / p10.
The solution here is to mark captures that occur within contract
assertion scopes and then clear that mark if we then see a normal
capture for the same entity - we must defer the error handling since
the following is valid:
auto f5 = [=] {
contract_assert (i > 0); // OK, i is referenced elsewhere.
return i;
};
PR c++/124648
gcc/cp/ChangeLog:
* cp-tree.h (DECL_CONTRACT_CAPTURE_P): New.
* parser.cc (cp_parser_lambda_body): Scan the captures for
ones were only added in contract assertion scopes. Issue
errors for those found.
* semantics.cc (process_outer_var_ref): Mark implicit
captures that occur in contract assertion scopes. Clear
the mark if the entity is subsequently captured 'normally'.
(set_contract_capture_flag): New.
gcc/testsuite/ChangeLog:
* g++.dg/contracts/cpp26/expr.prim.lambda.closure.p10.C: New test.
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
Co-authored-by: Jason Merrill <jason@redhat.com>1 parent 11c0183 commit 13e1fc2
4 files changed
Lines changed: 106 additions & 3 deletions
File tree
- gcc
- cp
- testsuite/g++.dg/contracts/cpp26
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
595 | 595 | | |
596 | 596 | | |
597 | 597 | | |
| 598 | + | |
598 | 599 | | |
599 | 600 | | |
600 | 601 | | |
| |||
5387 | 5388 | | |
5388 | 5389 | | |
5389 | 5390 | | |
| 5391 | + | |
| 5392 | + | |
| 5393 | + | |
| 5394 | + | |
| 5395 | + | |
| 5396 | + | |
| 5397 | + | |
5390 | 5398 | | |
5391 | 5399 | | |
5392 | 5400 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13737 | 13737 | | |
13738 | 13738 | | |
13739 | 13739 | | |
| 13740 | + | |
| 13741 | + | |
| 13742 | + | |
| 13743 | + | |
| 13744 | + | |
| 13745 | + | |
| 13746 | + | |
| 13747 | + | |
| 13748 | + | |
| 13749 | + | |
| 13750 | + | |
| 13751 | + | |
| 13752 | + | |
| 13753 | + | |
| 13754 | + | |
| 13755 | + | |
| 13756 | + | |
| 13757 | + | |
| 13758 | + | |
| 13759 | + | |
| 13760 | + | |
13740 | 13761 | | |
13741 | 13762 | | |
13742 | 13763 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4575 | 4575 | | |
4576 | 4576 | | |
4577 | 4577 | | |
| 4578 | + | |
| 4579 | + | |
| 4580 | + | |
| 4581 | + | |
| 4582 | + | |
| 4583 | + | |
| 4584 | + | |
| 4585 | + | |
| 4586 | + | |
| 4587 | + | |
| 4588 | + | |
| 4589 | + | |
4578 | 4590 | | |
4579 | 4591 | | |
4580 | 4592 | | |
| |||
4619 | 4631 | | |
4620 | 4632 | | |
4621 | 4633 | | |
| 4634 | + | |
| 4635 | + | |
| 4636 | + | |
| 4637 | + | |
| 4638 | + | |
4622 | 4639 | | |
4623 | 4640 | | |
4624 | 4641 | | |
| |||
4667 | 4684 | | |
4668 | 4685 | | |
4669 | 4686 | | |
4670 | | - | |
| 4687 | + | |
4671 | 4688 | | |
4672 | | - | |
4673 | | - | |
| 4689 | + | |
| 4690 | + | |
| 4691 | + | |
| 4692 | + | |
| 4693 | + | |
| 4694 | + | |
4674 | 4695 | | |
4675 | 4696 | | |
4676 | 4697 | | |
| |||
Lines changed: 53 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
0 commit comments