Issue 127471
Summary [clang-tidy] False negative modernize-use-integer-sign-comparison without cast?
Labels clang-tidy
Assignees
Reporter chrchr-github
    ~~~c++
#include <vector>

bool f(int i, const std::vector<int>& v) {
    return i >= v.size();
}
bool g(int i, const std::vector<int>& v) {
    return i >= static_cast<int>(v.size()); // warning
}
bool h(int i, const std::vector<int>& v) {
    return static_cast<std::size_t>(i) >= v.size();
}

int main() {
    return f(-1, {});
}
~~~
~~~
<source>:7:12: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
    1 | #include <vector>
    2 | 
    3 | bool f(int i, const std::vector<int>& v) {
    4 |     return i >= v.size();
    5 | }
    6 | bool g(int i, const std::vector<int>& v) {
    7 |     return i >= static_cast<int>(v.size());
 |            ^ ~~~~~~~~~~~~~~~~~~~~         
      | std::cmp_greater_equal( ,      )
1 warning generated.
~~~
I wonder if the observed behavior is intentional (warning only for `g()`, but not for `f()` and `h()`).
https://godbolt.org/z/8GWMrh781
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to