whisperity added a comment.

While I understand extending the analyzer to cover more is a good approach, 
there is `-Wconversion` which seemingly covers this -- or at least the trivial 
case(?):

  #include <cstdio>
  #include <vector>
  
  void foo(unsigned x)
  {
    printf("%u\n", x);
  }
  
  int main()
  {
    int i = -1;
    foo(i);
  
    std::vector<int> x;
    x[i] = 5;
  }



  $ clang++ -Wconversion -o/dev/null check.cpp 
  check.cpp:12:7: warning: implicit conversion changes signedness: 'int' to 
'unsigned int' [-Wsign-conversion]
    foo(i);
    ~~~ ^
  check.cpp:15:5: warning: implicit conversion changes signedness: 'int' to 
'std::vector::size_type' (aka 'unsigned long') [-Wsign-conversion]
    x[i] = 5;
    ~ ^


Repository:
  rC Clang

https://reviews.llvm.org/D46081



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to