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 extern "C" {
5   int abs(int);
6   float fabsf(float);
7 }
8 
9 namespace std {
10   int abs(int);
11   float abs(float);
12 }
13 
14 void test(long long ll, double d, int i, float f) {
15   // Suggest including cmath
16   (void)abs(d);
17   // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}}
18   // expected-note@-2{{use function 'std::abs' instead}}
19   // expected-note@-3{{include the header <cmath> or explicitly provide a declaration for 'std::abs'}}
20   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"std::abs"
21 
22   (void)fabsf(d);
23   // expected-warning@-1{{absolute value function 'fabsf' given an argument of type 'double' but has parameter of type 'float' which may cause truncation of value}}
24   // expected-note@-2{{use function 'std::abs' instead}}
25   // expected-note@-3{{include the header <cmath> or explicitly provide a declaration for 'std::abs'}}
26   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:14}:"std::abs"
27 
28   // Suggest including cstdlib
29   (void)abs(ll);
30   // 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}}
31   // expected-note@-2{{use function 'std::abs' instead}}
32   // expected-note@-3{{include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}}
33   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"std::abs"
34   (void)fabsf(ll);
35   // expected-warning@-1{{using floating point absolute value function 'fabsf' when argument is of integer type}}
36   // expected-note@-2{{use function 'std::abs' instead}}
37   // expected-note@-3{{include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}}
38   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:14}:"std::abs"
39 
40   // Proper function already called, no warnings.
41   (void)abs(i);
42   (void)fabsf(f);
43 
44   // Declarations found, suggest name change.
45   (void)fabsf(i);
46   // expected-warning@-1{{using floating point absolute value function 'fabsf' when argument is of integer type}}
47   // expected-note@-2{{use function 'std::abs' instead}}
48   // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs"
49   (void)abs(f);
50   // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}}
51   // expected-note@-2{{use function 'std::abs' instead}}
52   // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"std::abs"
53 }
54