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