std::construct_at should support arrays
Jonathan Wakely

Created on 2020-04-29.00:00:00 last changed 2 weeks ago


Date: 2020-05-15.00:00:00

[ 2020-05-09; Reflector prioritization ]

Set priority to 2 after reflector discussions.

Date: 2020-04-29.00:00:00

std::construct_at is ill-formed for array types, because the type of the new-expression is T not T* so it cannot be converted to the return type.

In C++17 allocator_traits::construct did work for arrays, because it returns void so there is no ill-formed conversion. On the other hand, in C++17 allocator_traits::destroy didn't work for arrays, because p->~T() isn't valid.

In C++20 allocator_traits::destroy does work, because std::destroy_at treats arrays specially, but allocator_traits::construct no longer works because it uses std::construct_at.

It seems unnecessary and/or confusing to remove support for arrays in construct when we're adding it in destroy.

I suggest that std::construct_at should also handle arrays. It might be reasonable to restrict that support to the case where sizeof...(Args) == 0, if supporting parenthesized aggregate-initialization is not desirable in std::construct_at.

Date User Action Args
2020-05-09 19:39:43adminsetmessages: + msg11278
2020-04-29 00:00:00admincreate