Home | History | Annotate | Download | only in Sema
      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 
      4 int abs(int);
      5 
      6 // Wrong signature
      7 int fabsf(int);
      8 // expected-warning@-1{{incompatible redeclaration of library function 'fabsf'}}
      9 // expected-note@-2{{'fabsf' is a builtin with type 'float (float)'}}
     10 
     11 void test_int(int i, unsigned u, long long ll, float f, double d) {
     12   (void)abs(i);
     13 
     14   // Remove abs call
     15   (void)abs(u);
     16   // expected-warning@-1{{taking the absolute value of unsigned type 'unsigned int' has no effect}}
     17   // expected-note@-2{{remove the call to 'abs' since unsigned values cannot be negative}}
     18   // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:""
     19 
     20   int llabs;
     21   (void)llabs;
     22   // Conflict in names, no notes
     23   (void)abs(ll);
     24   // 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}}
     25 
     26   // Conflict in names, no notes
     27   (void)abs(f);
     28   // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}}
     29 
     30   // Suggest header.
     31   (void)abs(d);
     32   // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}}
     33   // expected-note@-2{{use function 'fabs' instead}}
     34   // expected-note@-3{{include the header <math.h> or explicitly provide a declaration for 'fabs'}}
     35   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"fabs"
     36 }
     37