2961. Bad postcondition for set_default_resource

Section: 23.12.4 [mem.res.global] Status: WP Submitter: Casey Carter Opened: 2017-05-09 Last modified: 2017-07-30

Priority: Not Prioritized

View all issues with WP status.

Discussion:

The specification of set_default_resource in N4659 23.12.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 23.12.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 23.12.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: […]