This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++20 status.

2961. Bad postcondition for set_default_resource

Section: 20.4.4 [mem.res.global] Status: C++20 Submitter: Casey Carter Opened: 2017-05-09 Last modified: 2021-02-25

Priority: Not Prioritized

View all other issues in [mem.res.global].

View all issues with C++20 status.

Discussion:

The specification of set_default_resource in N4659 20.4.4 [mem.res.global] reads:

memory_resource* set_default_resource(memory_resource* r) noexcept;

-4- Effects: If r is non-null, sets the value of the default memory resource pointer to r, otherwise sets the default memory resource pointer to new_delete_resource().

-5- Postconditions: get_default_resource() == r.

-6- Returns: The previous value of the default memory resource pointer.

-7- Remarks: […]

It is apparent that the effects specified in para 4 cannot — and indeed should not — achieve the postcondition specified in para 5 when r is null.

[2017-05-13, Tim comments]

This is the same issue as LWG 2522, which just missed the Fundamentals TS working draft used for the merge. A similar resolution (simply striking the Postconditions: paragraph) might be better.

Previous resolution [SUPERSEDED]:

This wording is relative to N4659.

  1. Modify 20.4.4 [mem.res.global] as follows:

    memory_resource* set_default_resource(memory_resource* r) noexcept;
    

    -4- Effects: If r is non-null, sets the value of the default memory resource pointer to r, otherwise sets the default memory resource pointer to new_delete_resource().

    -5- Postconditions: If r is non-null, get_default_resource() == r. Otherwise, get_default_resource() == new_delete_resource().

    -6- Returns: The previous value of the default memory resource pointer.

    -7- Remarks: […]

[2017-06-13, Casey Carter revises proposed wording]

I suggest to strike the Postconditions paragraph ([mem.res.global]/5) completely, as in LWG 2522

[2017-06-15, Moved to Tentatively Ready after 6 positive votes on c++std-lib]

Proposed resolution:

This wording is relative to N4659.

  1. Modify 20.4.4 [mem.res.global] as follows:

    memory_resource* set_default_resource(memory_resource* r) noexcept;
    

    -4- Effects: If r is non-null, sets the value of the default memory resource pointer to r, otherwise sets the default memory resource pointer to new_delete_resource().

    -5- Postconditions: get_default_resource() == r.

    -6- Returns: The previous value of the default memory resource pointer.

    -7- Remarks: […]