You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
operatornew[](sizeof(T) * 5 + x)
operatornew[](sizeof(T) * 5 + x, std::align_val_t(alignof(T)))
operatornew[](sizeof(T) * 5 + x, 2, f)
operatornew[](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])).
The text was updated successfully, but these errors were encountered:
I don't think using alignof(T[5]) improves consistency.
In this example, 5 is a constant expression, so we happen to be able to write std::align_val_t(alignof(T[5])). However, if one uses n that is not a constant expression, the expositing expression needs to fall back to use alignof(T). So it's arguably more consistent to always mention the element type only.
I don't think using alignof(T[5]) improves consistency.
In this example, 5 is a constant expression, so we happen to be able to write std::align_val_t(alignof(T[5])). However, if one uses n that is not a constant expression, the expositing expression needs to fall back to use alignof(T). So it's arguably more consistent to always mention the element type only.
We should separate the rule into two cases: one for array objects and one for the other.
[expr.new] p19 says
Anyway, for the type refers to the type of the allocated object. [expr.new] p20 gives a misleading example of array object
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]))
.The text was updated successfully, but these errors were encountered: