diff --git a/cpp/src/arrow/dataset/file_ipc.cc b/cpp/src/arrow/dataset/file_ipc.cc index 8e19b2bbee2a..da427a450d57 100644 --- a/cpp/src/arrow/dataset/file_ipc.cc +++ b/cpp/src/arrow/dataset/file_ipc.cc @@ -145,9 +145,9 @@ Result IpcFileFormat::ScanBatchesAsync( auto reopen_reader = [self, options, source](std::shared_ptr reader) -> Future> { - ARROW_ASSIGN_OR_RAISE(auto options, + ARROW_ASSIGN_OR_RAISE(auto read_options, GetReadOptions(*reader->schema(), *self, *options)); - return OpenReader(source, options); + return OpenReader(source, read_options); }; auto readahead_level = options->batch_readahead; auto default_fragment_scan_options = this->default_fragment_scan_options; diff --git a/cpp/src/arrow/result.h b/cpp/src/arrow/result.h index 564e2848bf3a..449b5e3bf393 100644 --- a/cpp/src/arrow/result.h +++ b/cpp/src/arrow/result.h @@ -465,10 +465,25 @@ class [[nodiscard]] Result : public util::EqualityComparable> { } }; -#define ARROW_ASSIGN_OR_RAISE_IMPL(result_name, lhs, rexpr) \ - auto&& result_name = (rexpr); \ - ARROW_RETURN_IF_(!(result_name).ok(), (result_name).status(), ARROW_STRINGIFY(rexpr)); \ - lhs = std::move(result_name).ValueUnsafe(); +#if defined(__GNUC__) || defined(__clang__) +// For gcc and clang, we can avoid the intermediate `result_name` +// escaping the current scope by using a compiler extension. +// Otherwise, we fall back to an implementation where the intermediate +// declaration might consume additional stack space. +# define ARROW_ASSIGN_OR_RAISE_IMPL(result_name, lhs, rexpr) \ + lhs = __extension__({ \ + auto&& result_name = (rexpr); \ + ARROW_RETURN_IF_(!(result_name).ok(), (result_name).status(), \ + ARROW_STRINGIFY(rexpr)); \ + std::move(result_name).ValueUnsafe(); \ + }) +#else +# define ARROW_ASSIGN_OR_RAISE_IMPL(result_name, lhs, rexpr) \ + auto&& result_name = (rexpr); \ + ARROW_RETURN_IF_(!(result_name).ok(), (result_name).status(), \ + ARROW_STRINGIFY(rexpr)); \ + lhs = std::move(result_name).ValueUnsafe(); +#endif #define ARROW_ASSIGN_OR_RAISE_NAME(x, y) ARROW_CONCAT(x, y) @@ -482,7 +497,7 @@ class [[nodiscard]] Result : public util::EqualityComparable> { /// ValueType value; /// ARROW_ASSIGN_OR_RAISE(value, MaybeGetValue(arg)); /// -/// WARNING: ARROW_ASSIGN_OR_RAISE expands into multiple statements; +/// WARNING: ARROW_ASSIGN_OR_RAISE may expand into multiple statements; /// it cannot be used in a single statement (e.g. as the body of an if /// statement without {})! ///