Repository navigation
[C++][Compute] "error: unused variable ‘is_utf8’" can occur when building the Arrow C++ main branch #50752
Copy link
Copy link
Closed
Description
Problem
The following build error can occur when building the Arrow C++ main branch.
/arrow/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:1753:16: error: unused variable ‘is_utf8’ [-Werror=unused-variable]
1753 | const bool is_utf8 = is_string_or_string_view(batch[0].type()->id());
| ^~~~~~~
Reproduce
This error occurs under the following conditions:
- Use Debug build(Use -Werror)
- Specify ARROW_COMPUTE=ON
- Specify ARROW_WITH_RE2=OFF
Steps to reproduce:
mkdir arrow-cpp-build
git clone https://github.com/apache/arrow.git
cd arrow-cpp-build
cmake ../arrow/cpp --preset ninja-debug-minimal -DARROW_COMPUTE=ON -DARROW_WITH_RE2=OFF
cmake --build .
Cause
The is_utf8 variable introduced by commit 374db36 is unused when ARROW_WITH_RE2=OFF is specified.
static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) {
const MatchSubstringOptions& options = MatchSubstringState::Get(ctx);
+ const bool is_utf8 = is_string_or_string_view(batch[0].type()->id());
if (options.ignore_case) {
#ifdef ARROW_WITH_RE2
ARROW_ASSIGN_OR_RAISE(auto matcher,
- FindSubstringRegex::Make(options, InputType::is_utf8, true));
- applicator::ScalarUnaryNotNullStateful<OffsetType, InputType, FindSubstringRegex>
+ FindSubstringRegex::Make(options, is_utf8, true));
+ applicator::ScalarUnaryNotNullStateful<OffsetType, InputPhysicalType,
+ FindSubstringRegex>
kernel{std::move(matcher)};
return kernel.Exec(ctx, batch, out);
#else
return Status::NotImplemented("ignore_case requires RE2");
#endif
}
- applicator::ScalarUnaryNotNullStateful<OffsetType, InputType, FindSubstring> kernel{
- FindSubstring(PlainSubstringMatcher(options))};
+ applicator::ScalarUnaryNotNullStateful<OffsetType, InputPhysicalType, FindSubstring>
+ kernel{FindSubstring(PlainSubstringMatcher(options))};
return kernel.Exec(ctx, batch, out);
}
};Suggested fix
We can prevent this error by moving the declaration of is_utf8 inside the #ifdef ARROW_WITH_RE2 block as follows:
diff --git a/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc b/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc
index 06ec8c999c..8e7b626837 100644
--- a/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc
+++ b/cpp/src/arrow/compute/kernels/scalar_string_ascii.cc
@@ -1750,9 +1750,9 @@ struct FindSubstringExec {
static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) {
const MatchSubstringOptions& options = MatchSubstringState::Get(ctx);
- const bool is_utf8 = is_string_or_string_view(batch[0].type()->id());
if (options.ignore_case) {
#ifdef ARROW_WITH_RE2
+ const bool is_utf8 = is_string_or_string_view(batch[0].type()->id());
ARROW_ASSIGN_OR_RAISE(auto matcher,
FindSubstringRegex::Make(options, is_utf8, true));
applicator::ScalarUnaryNotNullStateful<OffsetType, InputPhysicalType,If this approach looks good to you, I'd be happy to open a PR.
Component(s)
C++
Reactions are currently unavailable
Activity
raulcd commentedon Jul 31, 2026
Thanks @komainu8 ! The solution you are proposing sounds reasonable to me. Feel free to open a PR, I'll assign the issue to you as there's lots of bots looking for quick PRs lately :)
komainu8 commentedon Jul 31, 2026
@raulcd Thank you for your comment.
I've opened a PR at #50754.
GH-50752: [C++][Compute] Fix unused variable warning when ARROW_WITH_…
raulcd commentedon Jul 31, 2026
Issue resolved by pull request 50754
#50754