Skip to content

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

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

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