cplusplus / cplusplus/draft

[expr.new] p20 Accurate the example for the allocation call in array new expression

Open
#5,930 2 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.