<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/88203>88203</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] false positive readability-container-size-empty
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          iillyyaa
      </td>
    </tr>
</table>

<pre>
    `std::regex_result` type has two methods: `difference_type length(size_type n = 0) const` and `bool empty() const`
However, they are not an exact match for each other with respect to the readability-container-size-empty check, in particular, when the index `n` is supplied, since there is no corresponding `empty(size_type n)` overload.

Yet, this (trimmed) code is claimed to violate the readability-container-size-empty check:
```c++
#include <regex>
#include <string>

bool test(const std::string& val) {
 static const std::regex re("([0-9]+)/([A-B]+)");
    if (std::smatch m; std::regex_match(val, m, re)) {
        return m.length(2) > 0;
 }
    return false;
}
```

Reported as:
```
/home/ilyak/veo/crux/app/bbr/key.cpp:37:9: error: the 'empty' method should be used to check for emptiness instead of 'length' [readability-container-size-empty,-warnings-as-errors]
   37 |     if (m.length(4) > 0) {
      |         ^~~~~~~~~~~~~~~
      | !m.empty()
/home/ilyak/veo/oe-scarthgap/tmp/build-glibc/sysroots/intel-skylake-64/usr/lib/x86_64-oe-linux/13.2.0/../../../include/c++/13.2.0/bits/regex.h:1887:7: note: method 'match_results'::empty() defined here
 1887 |       empty() const noexcept
      |       ^
```

Reproducible in clang-tidy (master) via: https://godbolt.org/z/eocdWo7j4
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU-P4rgT_TTFpRSUtglJDhzoP9Hv_Lus9tRy7IJ42rEj26GbOexnX9mEhukZzWgRmMiuclW996oiQtBHS7SD6hGq55WY4-D8TmtjzmchVr1T5x1syxAV8D3wvacjfbx6CrOJsC0xnifCQQSM7w5HioNTAfgeYVsqfTiQJyvpNVsZssc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