Title
polymorphic_allocator::allocate does not satisfy Cpp17Allocator requirements
Status
c++23
Section
[mem.res]
Submitter
Alisdair Meredith

Created on 2020-07-27.00:00:00 last changed 12 months ago

Messages

Date: 2022-02-10.12:58:57

Proposed resolution:

This wording is relative to N4885.

  1. Modify [mem.res.public] as indicated:

    [[nodiscard]] void* allocate(size_t bytes, size_t alignment = max_align);
    

    -2- Effects: Equivalent to: return Allocates storage by calling do_allocate(bytes, alignment); and implicitly creates objects within the allocated region of storage.

    -?- Returns: A pointer to a suitable created object ([intro.object]) in the allocated region of storage.

    -?- Throws: What and when the call to do_allocate throws.

Date: 2022-02-10.00:00:00

[ 2022-02-10 Approved at February 2022 virtual plenary. Status changed: Tentatively Ready → WP. ]

Date: 2022-01-15.00:00:00

[ 2022-01-31; Reflector poll ]

Set status to Tentatively Ready after seven votes in favour during reflector poll.

Date: 2021-05-20.00:00:00

[ 2021-05-20 Tim comments and updates wording ]

memory_resource::allocate is the PMR equivalent of malloc and operator new. It therefore needs the "suitable created object" wording (see [intro.object], [c.malloc]). This ensures that it creates the requisite array object automatically for all the allocation functions of polymorphic_allocator, and returns the correct pointer value in all cases.

Date: 2020-08-15.00:00:00

[ 2020-08-21; Reflector prioritization ]

Set priority to 3 after reflector discussions.

Previous resolution [SUPERSEDED]:

This wording is relative to N4861.

[Drafting note: The proposed wording is inspired by the example given in the "Assertion/note" column of the expression a.allocate(n) in table [tab:cpp17.allocator].]

  1. Modify [mem.res.public] as indicated:

    [[nodiscard]] void* allocate(size_t bytes, size_t alignment = max_align);
    

    -2- Effects: Equivalent to: return do_allocate(bytes, alignment);

    void* p = do_allocate(bytes, alignment);
    return launder(new (p) byte[bytes]);
    
Date: 2020-08-15.00:00:00

[ 2020-08-03; Billy comments ]

It's worth noting that the resolution of CWG 2382 has impact on implementors for this issue.

Date: 2020-07-27.00:00:00

With the adoption of P0593R6 in Prague, std::ptr::polymorphic_allocator no longer satisfies the of Cpp17Allocator requirements. Specifically, all calls to allocate(n) need to create an object for an array of n Ts (but not initialize any of those elements). std::pmr::polymorphic_allocator calls its underlying memory resource to allocate sufficient bytes of storage, but it does not create (and start the lifetime of) the array object within that storage.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-02-10 12:58:57adminsetmessages: + msg12346
2022-02-10 12:58:57adminsetstatus: ready -> wp
2022-01-31 09:53:14adminsetmessages: + msg12334
2022-01-31 09:53:14adminsetstatus: new -> ready
2021-05-21 01:30:39adminsetmessages: + msg11832
2020-08-21 13:34:21adminsetmessages: + msg11438
2020-08-03 19:47:49adminsetmessages: + msg11431
2020-08-02 17:02:36adminsetmessages: + msg11425
2020-07-27 00:00:00admincreate