Date: Mon, 19 Oct 2020 08:55:27 +0200
* Denis Kotov via Std-Discussion:
> This code:
> ```cpp
> Subscription subscribe() throws SubscriptionError;
>
> Subscription subscribe() throws {
> ...
> throw SubscriptionError{"Error", Payload};
> ...
> }
> ```
> translates to:
> ```cpp
> struct SubscribeResult {
> Subscription res;
> SubscriptionError err;
> };
>
> SubscribeResult subscribe();
>
> SubscribeResult subscribe() {
> ...
> return SubscribeResult{ .err = SubscriptionError{"Error", Payload} };
> ...
> }
> ```
Not that requires ABI work on many architectures in order to avoid
regressions when Subscription can be returned directly in a register,
but SubscribeResult cannot. Quite a few ABIs always return structs in
memory, or pack multiple fields into a single register (optimizing for
the case where the caller stores the result to the final place, rather
than unpacking it immediately, as it would with inline exception
handling).
There is a reason why the present scheme based on unwinding has been
called “zero-cost exception handling”, too.
Thanks,
Florian
> This code:
> ```cpp
> Subscription subscribe() throws SubscriptionError;
>
> Subscription subscribe() throws {
> ...
> throw SubscriptionError{"Error", Payload};
> ...
> }
> ```
> translates to:
> ```cpp
> struct SubscribeResult {
> Subscription res;
> SubscriptionError err;
> };
>
> SubscribeResult subscribe();
>
> SubscribeResult subscribe() {
> ...
> return SubscribeResult{ .err = SubscriptionError{"Error", Payload} };
> ...
> }
> ```
Not that requires ABI work on many architectures in order to avoid
regressions when Subscription can be returned directly in a register,
but SubscribeResult cannot. Quite a few ABIs always return structs in
memory, or pack multiple fields into a single register (optimizing for
the case where the caller stores the result to the final place, rather
than unpacking it immediately, as it would with inline exception
handling).
There is a reason why the present scheme based on unwinding has been
called “zero-cost exception handling”, too.
Thanks,
Florian
-- Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen, HRB 153243, Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
Received on 2020-10-19 01:55:37