https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90372

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
(In reply to marc from comment #0)

Please always include all details relevant to the report here for future
reference (in case the external references should become inaccessible).  The
test case:

#include <cstdio>
#include <memory>
#include <string>

using file_ptr = std::unique_ptr<FILE, decltype([](FILE* f){ if (f) fclose(f);
})>;

const std::string_view s = "Hello, World";

extern void may_throw() noexcept(false);

void two() {
    if (auto f = fopen(nullptr, nullptr)) {
        fwrite(s.data(), s.size(), 1, f);
        try {
            may_throw();
        } catch (...) {
            fclose(f);
            throw;
        }
        fclose(f);
    }
}

void one() {
    if (auto f = file_ptr{fopen(nullptr, nullptr)}) {
        fwrite(s.data(), s.size(), 1, f.get());
        may_throw();
    }
}

Reply via email to