Title
constexpr placement-new is too permissive
Status
ready
Section
7.7 [expr.const]
Submitter
Brian Bi

Created on 2024-07-10.00:00:00 last changed yesterday

Messages

Date: 2024-11-19.12:36:26

CWG 2024-11-19

The proposed resolution does not address the ambiguity with different union members of the same type, but is a good fix to increase consistency with static_cast regardless.

Date: 2024-08-16.19:45:15

Proposed resolution (approved by CWG 2024-08-16):

Change in 7.7 [expr.const] bullet 5.18.2 as follows:

  • the selected allocation function is a non-allocating form (17.6.3.4 [new.delete.placement]) with an allocated type T, where
    • the placement argument to the new-expression points to an object that is pointer-interconvertible with an object of whose type is similar to T (7.3.6 [conv.qual]) or, if T is an array type, with to the first element of an object of a type similar to T, and
    • the placement argument points to storage whose duration began within the evaluation of E;
Date: 2024-08-16.19:45:15

constexpr placement new requires (just) pointer-interconvertibility for the argument pointer, whereas static_cast from void* to T* requires similarity. Requiring pointer-interconvertibility would not allow to differentiate two members of some union of the same type; such differentiation is required diagnose access to inactive union members.

History
Date User Action Args
2024-11-19 12:36:26adminsetmessages: + msg7903
2024-11-19 12:36:26adminsetstatus: tentatively ready -> ready
2024-08-16 19:45:15adminsetmessages: + msg7800
2024-08-16 19:45:15adminsetstatus: open -> tentatively ready
2024-07-10 00:00:00admincreate