llvm-project/clang/test/Analysis/conversion.cpp
Gabor Marton bd9e23943a [analyzer] Expand conversion check to check more expressions for overflow and underflow
This expands checking for more expressions. This will check underflow
and loss of precision when using call expressions like:

  void foo(unsigned);
  int i = -1;
  foo(i);

This also includes other expressions as well, so it can catch negative
indices to std::vector since it uses unsigned integers for [] and .at()
function.

Patch by: @pfultz2

Differential Revision: https://reviews.llvm.org/D46081
2021-12-15 11:41:34 +01:00

23 lines
424 B
C++

// RUN: %clang_analyze_cc1 -Wno-conversion -Wno-tautological-constant-compare -analyzer-checker=core,alpha.core.Conversion -verify %s
// expected-no-diagnostics
void dontwarn1() {
unsigned long x = static_cast<unsigned long>(-1);
}
void dontwarn2(unsigned x) {
if (x == static_cast<unsigned>(-1)) {
}
}
struct C {
C(unsigned x, unsigned long y) {}
};
void f(C) {}
void functioncall1(long x) {
f(C(64, x));
}