warn-absolute-value-header.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s -Wabsolute-value
  2. // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only %s -Wabsolute-value -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s
  3. int abs(int);
  4. // Wrong signature
  5. int fabsf(int);
  6. // expected-warning@-1{{incompatible redeclaration of library function 'fabsf'}}
  7. // expected-note@-2{{'fabsf' is a builtin with type 'float (float)'}}
  8. void test_int(int i, unsigned u, long long ll, float f, double d) {
  9. (void)abs(i);
  10. // Remove abs call
  11. (void)abs(u);
  12. // expected-warning@-1{{taking the absolute value of unsigned type 'unsigned int' has no effect}}
  13. // expected-note@-2{{remove the call to 'abs' since unsigned values cannot be negative}}
  14. // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:""
  15. int llabs;
  16. (void)llabs;
  17. // Conflict in names, no notes
  18. (void)abs(ll);
  19. // expected-warning@-1{{absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value}}
  20. // Conflict in names, no notes
  21. (void)abs(f);
  22. // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}}
  23. // Suggest header.
  24. (void)abs(d);
  25. // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}}
  26. // expected-note@-2{{use function 'fabs' instead}}
  27. // expected-note@-3{{include the header <math.h> or explicitly provide a declaration for 'fabs'}}
  28. // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"fabs"
  29. }