createcentury commented on issue #51834:
URL: https://github.com/apache/arrow/issues/51834#issuecomment-6088935425
Looking at how Chromium addresses this in `base/types/expected_macros.h`
(around `ASSIGN_OR_RETURN`), they faced the exact same language constraints:
1. Chromium also expands `ASSIGN_OR_RETURN` into multiple flat statements in
the caller's scope (using `BASE_UNIQUIFY(_expected_value)`).
2. Consequently, their temporaries live for the enclosing scope just as
Arrow's current implementation does. They document this trade-off explicitly:
```cpp
// WARNING: Expands into multiple statements; cannot be used in a single
// statement (e.g. as the body of an if statement without {})!
```
Because portable standard C++ cannot simultaneously:
* Allow `lhs` to be a variable declaration in the enclosing scope
* Early-return from the enclosing function on error
* Destruct the intermediate `Result`/`expected` at the statement/expression
boundary
Any attempt to solve this portably either breaks `auto var` declarations or
requires non-standard extensions.
Therefore, guarding the `__extension__({ ... })` statement expression
specifically for GCC / Clang (where deep recursion in server workloads is most
critical) while leaving the existing multi-statement expansion for MSVC seems
like the most practical approach. MSVC users would retain today's baseline
behavior without introducing breakage or unportable constructs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]