Skip to content

[C++][Compute] "error: unused variable ‘is_utf8’" can occur when building the Arrow C++ main branch #50752

Closed

Description

@komainu8

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++

Activity

  1. raulcd commented on Jul 31, 2026

    @raulcd
    Member

    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 :)

  2. komainu8 commented on Jul 31, 2026

    @komainu8
    ContributorAuthor

    @raulcd Thank you for your comment.
    I've opened a PR at #50754.

  3. added a commit that references this issue on Jul 31, 2026
  4. added this to the 26.0.0 milestone on Jul 31, 2026
  5. raulcd commented on Jul 31, 2026

    @raulcd
    Member

    Issue resolved by pull request 50754
    #50754

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions