[expr.delete] p7 The time of calling a deallocation function
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
Description
If the value of the operand of the delete-expression is not a null pointer value, then:
- [...]
- Otherwise, if the allocation was extended or was provided by extending the allocation of another new-expression, and the delete-expression for every other pointer value produced by a new-expression that had storage provided by the extended new-expression has been evaluated, the delete-expression shall call a deallocation function. The value returned from the allocation call of the extended new-expression shall be passed as the first argument to the deallocation function.
- Otherwise, the delete-expression will not call a deallocation function.
Consider this example
struct Container{
char memory[2];
};
auto ptr0 = new Container; //#0
auto ptr1 = new char; // #1
auto ptr2 = new char; //#2
delete ptr1; //#3
delete ptr2; //#4
delete ptr0; //#5
Assume the new-expression at #0 has been extended to provide the storage for #1 and #2. Note the emphasized wording in the second bullet, since there are only two new-expression that use the allocation provided by #0, hence at this point at #4, could we say the delete-expression for every other pointer value(...) has been evaluated? So, the deallocation function shall be called at #4? At the point of #5, the second bullet is also satisfied, hence it again call the deallocation function? Obviously, it does not make sense however it is what the second bullet saying.
I think the second bullet is intend to cover the following case
auto ptr0 = new Container; //#0
auto ptr1 = new char; // #1
auto ptr2 = new char; //#2
delete ptr1; //#3
delete ptr0; //#5
delete ptr2; //#4
This example is based on the first by adjusting the order of the delete-expression whose operand is produced by the extended allocation. The second bullet can work fine in this example, since #4 has not been evaluated, hence #5 cannot invoke the deallocation function, it's the responsibility of #4. However, as aforementioned, the second bullet seems not good at the first example.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the quoted [expr.delete] wording and the two allocation/deallocation examples in issue #4850. Trace which delete-expressions satisfy the second bullet, then compare the intended sequencing with the current standard text; done means the ambiguity is resolved and the wording or interpretation is agreed upon.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100