[expr.new] p20 Accurate the example for the allocation call in array new expression
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
Description
[expr.new] p19 says
Overload resolution is performed on a function call created by assembling an argument list.
The first argument is the amount of space requested, and has type std::size_t. If the type of the allocated object has new-extended alignment, the next argument is the type's alignment, and has type std::align_val_t. If the new-placement syntax is used, the initializer-clauses in its expression-list are the succeeding arguments. If no matching function is found then:
- [...]
- otherwise, an argument that is the type's alignment and has type std::align_val_t is added into the argument list immediately after the first argument;
Anyway, for the type refers to the type of the allocated object. [expr.new] p20 gives a misleading example of array object
new T[5] results in one of the following calls:
operator new[](sizeof(T) * 5 + x)
operator new[](sizeof(T) * 5 + x, std::align_val_t(alignof(T)))
operator new[](sizeof(T) * 5 + x, 2, f)
operator new[](sizeof(T) * 5 + x, std::align_val_t(alignof(T)), 2, f)
In such two cases, we specify the argument with the form std::align_val_t(alignof(T)), which is the alignment of the type of the element of the array, even though the alignment of the array type is equivalent to that of the type of the element according to [expr.alignof] p3. Note that the allocated object is an array.
In order to be consistent with what the rule exactly says, we should use std::align_val_t(alignof(T[5])).
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
Locate the source text for [expr.new] p20 and compare its array-new example with the wording in [expr.new] p19. Update the example to use the array type's alignment expression, then build the draft or run its documentation checks to confirm the rendered standard remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100