SC22WG21_Papers icon indicating copy to clipboard operation
SC22WG21_Papers copied to clipboard

make_unique_resource_checked exception safety

Open thinkoid opened this issue 6 years ago • 0 comments

Unlike std::make_unique which does not allow the passing of a custom deleter, this factory does. A deleter whose construction can throw would leak like in the following contrived test case:

int x = 1;

struct S {
    S () { throw 0; }
    void operator() (int) const { x = 0; }
};

int main () {
    try {
        stdx::make_unique_resource_checked (x, 0, S{ });
    }
    catch (...) {
        assert (0 == x);
    }

    return 0;
}

The assertion fails. One could amend the specification to ask that the deleter construction doesn't throw, along the lines of a similar specification for the deleter of std::unique_ptr (e.g., 32.11.1.2.1p5). Is this something that popped up in the previous discussions you had in LWG?

thinkoid avatar Oct 29 '18 22:10 thinkoid