# clang-tidy readability-container-size-empty on repo: fix changes the outcome of the project's command

Evidence sheet generated by fixhunt from a repository scan. Not an issue text. A human re-verifies, checks the
duplicates below, and writes the upstream report in their own words following the project's AI policy.

- Tool: clang-tidy 21.1.8 (fix labelled unknown)
- Project: /home/sun/dev/diaghunt/demo/repo
- Command: `make -s -C native test` (exit 0 before, 2 after)
- Files changed by the fix: 1; smallest change that still reproduces: 1 of 1 hunk(s) in native/src/window.cpp
- Sites reported by the rule in the changed files: 1 before, 0 after the fix
- Judge (Nemotron 3 Ultra, advisory): real, severity high. The rule rewrites `w.size() == 0` to `w.empty()`, which for standard containers is semantically equivalent. However, the test failure indicates that `Window::empty()` either does not exist, has a different signature, or returns a different result than `w.size() == 0`. Since the documentation is missing and the fix is labelled unknown, the rewrite cannot be assumed safe for this user-defined type, and the change in test outcome demonstrates a real behavioral regression.

## Change (applies to the project with `git apply -p1`)

```diff
--- a/native/src/window.cpp
+++ b/native/src/window.cpp
@@ -9,4 +9,4 @@
 
 int Window::sum() const { return std::accumulate(samples_.begin(), samples_.end(), 0); }
 
-bool disabled(const Window& w) { return w.size() == 0; }
+bool disabled(const Window& w) { return w.empty(); }
```

## Observed

```
stdout lines only before the fix:
  ok   !disabled(w)
  PASSED
stdout lines only after the fix:
  FAIL !disabled(w)
  FAILED
exit 0 → 2
stderr last line before: (none)
stderr last line after: make: *** [Makefile:6: test] Error 1
```

## Output of the command (last 40 lines)

Before:

```
ok   !disabled(w)
ok   w.empty()
ok   w.sum() == 9
ok   disabled(off)
ok   normalize("MiXed") == "mixed"
ok   first_or_null("") == NULL
ok   std::strcmp(first_or_null("a"), "a") == 0
PASSED
```

After:

```
FAIL !disabled(w)
ok   w.empty()
ok   w.sum() == 9
ok   disabled(off)
ok   normalize("MiXed") == "mixed"
ok   first_or_null("") == NULL
ok   std::strcmp(first_or_null("a"), "a") == 0
FAILED
stderr:
make: *** [Makefile:6: test] Error 1
```

## Why the rewrite is not equivalent (model draft, verify before use)

The rewrite replaces `w.size() == 0` with `w.empty()`, which for standard containers like `std::vector` or `deque` is equivalent in behavior—both check if there are zero elements. However, if `Window::size()` returns a signed integer type (e.g., `int`) while `empty()` expects an unsigned comparison internally, or if `Window` overrides `size()` with non-standard semantics (e.g., returning cached or approximated size), then `w.size() == 0` and `w.empty()` may diverge. For instance, if `size()` can be negative due to overflow or bug, `w.size() == 0` would be false for negative values, but `w.empty()` might still return true if the container is actually empty—though this contradicts typical design. More plausibly, if `Window` is not a standard container and `empty()` is not overridden to match `size() == 0`, the two expressions differ. The test failure indicates that for some `w`, `w.size() == 0` is true but `w.empty()` is false (or vice versa), breaking equivalence. Since the fix assumes `empty()` mirrors `size() == 0`, it fails when `Window` does not uphold that contract—making the change unsafe without verifying `Window`'s actual behavior. The observed shift from passing to failing confirms the semantic mismatch.

## Upstream search

Queries: "readability-container-size-empty fix", "readability-container-size-empty size zero comparison", "clang-tidy readability-container-size-empty empty method", "Window disabled function size equals zero"

- related: https://github.com/llvm/llvm-project/issues/171193
- related: https://github.com/llvm/llvm-project/issues/154762
- related: https://github.com/llvm/llvm-project/issues/152387
- related: https://github.com/llvm/llvm-project/issues/37603
- related: https://github.com/llvm/llvm-project/issues/118418
- related: https://github.com/llvm/llvm-project/issues/162287
- related: https://github.com/llvm/llvm-project/issues/185007
- related: https://github.com/llvm/llvm-project/issues/88203
- related: https://github.com/llvm/llvm-project/issues/72619
- related: https://github.com/llvm/llvm-project/issues/51118

## Reproduce

```sh
clang-tidy-21 -checks=-*,readability-container-size-empty --fix native/src/window.cpp -- -std=c++20 -Wall -Inative/include
make -s -C native test
```
