From 1a2361ee2fb96d6976900583f6079dad762e5a4b Mon Sep 17 00:00:00 2001 From: Jin Shang Date: Tue, 30 Aug 2022 23:23:44 +0800 Subject: [PATCH] ARROW-17567: [C++] Avoid internal compiler error with gcc 7 and c++17 (#14004) The current compute kernel fails to compile with gcc6/7 and c++14/17, due to a known bug of gcc. It is triggered when a const integer is capture by reference in a lambda function, and is parenthesized in that lambda code. Capturing the const ints by value fixes this issue. See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83204 and https://github.com/kokkos/kokkos-kernels/issues/349 Lead-authored-by: Jin Shang Co-authored-by: Antoine Pitrou Co-authored-by: jinshang Signed-off-by: Antoine Pitrou --- cpp/src/arrow/compute/kernels/aggregate_internal.h | 3 ++- cpp/src/arrow/compute/kernels/scalar_set_lookup.cc | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cpp/src/arrow/compute/kernels/aggregate_internal.h b/cpp/src/arrow/compute/kernels/aggregate_internal.h index 8db74bfe0cd80..8fd67485d7fb1 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_internal.h +++ b/cpp/src/arrow/compute/kernels/aggregate_internal.h @@ -164,7 +164,8 @@ enable_if_t::value, SumType> SumArray( // reduce summation of one block (may be smaller than kBlockSize) from leaf node // continue reducing to upper level if two summations are ready for non-leaf node - auto reduce = [&](SumType block_sum) { + // (capture `levels` by value because of ARROW-17567) + auto reduce = [&, levels](SumType block_sum) { int cur_level = 0; uint64_t cur_level_mask = 1ULL; sum[cur_level] += block_sum; diff --git a/cpp/src/arrow/compute/kernels/scalar_set_lookup.cc b/cpp/src/arrow/compute/kernels/scalar_set_lookup.cc index 7a0834058f07f..292a924233b49 100644 --- a/cpp/src/arrow/compute/kernels/scalar_set_lookup.cc +++ b/cpp/src/arrow/compute/kernels/scalar_set_lookup.cc @@ -67,8 +67,11 @@ struct SetLookupState : public KernelState { auto visit_valid = [&](T v) { const auto memo_size = static_cast(memo_index_to_value_index.size()); int32_t unused_memo_index; - auto on_found = [&](int32_t memo_index) { DCHECK_LT(memo_index, memo_size); }; - auto on_not_found = [&](int32_t memo_index) { + // (capture `memo_size` by value because of ARROW-17567) + auto on_found = [&, memo_size](int32_t memo_index) { + DCHECK_LT(memo_index, memo_size); + }; + auto on_not_found = [&, memo_size](int32_t memo_index) { DCHECK_EQ(memo_index, memo_size); memo_index_to_value_index.push_back(index); }; @@ -79,8 +82,10 @@ struct SetLookupState : public KernelState { }; auto visit_null = [&]() { const auto memo_size = static_cast(memo_index_to_value_index.size()); - auto on_found = [&](int32_t memo_index) { DCHECK_LT(memo_index, memo_size); }; - auto on_not_found = [&](int32_t memo_index) { + auto on_found = [&, memo_size](int32_t memo_index) { + DCHECK_LT(memo_index, memo_size); + }; + auto on_not_found = [&, memo_size](int32_t memo_index) { DCHECK_EQ(memo_index, memo_size); memo_index_to_value_index.push_back(index); };