[all-commits] [llvm/llvm-project] 7279e4: [benchmark] Fix -Wunused-but-set-variable warning ...

original-cooling-space via All-commits all-commits at lists.llvm.org
Mon Aug 3 08:27:16 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7279e4042d207b077ca752af7b982bd6e745b7f4
      https://github.com/llvm/llvm-project/commit/7279e4042d207b077ca752af7b982bd6e745b7f4
  Author: original-cooling-space <zhangweize9 at gmail.com>
  Date:   2026-08-03 (Mon, 03 Aug 2026)

  Changed paths:
    M third-party/benchmark/test/basic_test.cc

  Log Message:
  -----------
  [benchmark] Fix -Wunused-but-set-variable warning in basic_test (#213637)

Fix a build error when building benchmark unit tests with modern
GCC/Clang compilers under strict warning options (-Werror).

In `test/basic_test.cc`, the variable `sum` in `BM_OneTemplateFunc` was
assigned but never read, triggering `-Wunused-but-set-variable`.

Silenced the warning by marking sum with `[[maybe_unused]]`, preserving
the benchmark function's logic while ensuring clean build output.

### Description  
Fixes a build error when compiling `third-party/benchmark` unit tests
with modern GCC/Clang compilers under `-Werror`.

In `test/basic_text.cc`, the variable `sum` in `BM_OneTemplatcFunc` was
assigned but never read, triggering `-Wunused-but-set-variable`.

### Solution  
Silenced the warning by marking sum with `[[maybe_unused]]`, preserving
the benchmark function's logic while ensuring clean build output.

### Test Plan  
1. Configured CMake with `-DBENCHMARK_ENABLE_TESTING=ON` and
`-DBENCHMARK_ENABLE_WERROR=ON`.
2. Built the target: `cmake --build build -j$(nproc)` -> Build succeed
with zero warnings/errors.
3. Executed unit tests: `ctest --test-dir build` -> 100% test passed.  

### Environment  
- **OS**: Linux (6.6.87.2-microsoft-standard-WSL2)  
- **Compiler**: Clang 22.1.8 / GCC 16.1.1 20260728  
- **CMake**: 4.4.2



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list