given the following code
#include <regex>
void foo() {
std::smatch match;
if (match.length());
}
clang-tidy will suggest to replace match.length() with !match.empty(); however, this is invalid because for successful matches of zero length, match.length() == 0 and match.empty() == false.
godbolt sample demonstrating clang-tidy's incorrect diagnostic https://godbolt.org/z/qnzc4Pcrc
godbolt sample demonstrating a zero length match (execute the code) https://godbolt.org/z/YvT7hb4f4
regex 101 sample demonstrating a zero length regex & match https://regex101.com/r/dzUrRp/1
Related: #88203