A container's size() or length() is compared with zero, where empty() says the same directly

tx0/cpp:size-compared-with-zeroallnotestyle/conventionsdepth faststyle

What it finds

v.size() == 0 and v.size() > 0 ask whether the container is empty; empty() says so and is constant time for every container. The fix rewrites the comparison; it is offered, as unsafe, only for a variable the file declares as a standard container, string, string view or span, since other classes with size() may have no empty().

From the rule's source, size_compared_with_zero.rs.

Turn it on, off or suppress it

The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/cpp:size-compared-with-zero" = "note"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/cpp:size-compared-with-zero] reason="..."

tx0 explain tx0/cpp:size-compared-with-zero shows the same in the terminal. Found a false positive? Report it.