C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Execute statement when leaving scope

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Mon, 12 Dec 2022 20:20:59 +0000
On 12 December 2022 20:13:40 GMT, Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> wrote:
>On Mon, Dec 12, 2022 at 3:06 PM Lénárd Szolnoki via Std-Proposals
><std-proposals_at_[hidden]> wrote:
>>
>> Hi,
>>
>> On 12 December 2022 09:58:22 GMT, Ville Voutilainen via Std-Proposals <std-proposals_at_[hidden]> wrote:
>> >That's because it's in gcc 13,
>> >https://gcc.gnu.org/gcc-13/changes.html
>> >
>> >
>> > - Support for the <experimental/scope> header from v3 of the Library
>> > Fundamentals Technical Specification.
>>
>> Interesting. I'm not very impressed with the generated code for scope_success:
>>
>> https://godbolt.org/z/joYGhjqKa
>>
>> I believe that f1 and f2 are equivalent.
>
>They are not equivalent. `scope_success` means "call this function if
>the scope is not exiting due to an exception being thrown from within
>the scope." `scope_fail` means exiting due to an exception.

But in f1 bar() is not called when foo() throws. Same happens in f2. If I used scope_exit then bar() would be called unconditionally.

Received on 2022-12-12 20:21:02