blob: 925be38ace08783db605511ee07965cb9c34a38f [file] [log] [blame]
Richard Trieu7eb0b2c2014-02-26 01:17:28 +00001// 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
Richard Trieubeffb832014-04-15 23:47:53 +00004extern "C" {
5 int abs(int);
6 float fabsf(float);
7}
Richard Trieu7eb0b2c2014-02-26 01:17:28 +00008
Richard Trieubeffb832014-04-15 23:47:53 +00009namespace std {
10 int abs(int);
11 float abs(float);
12}
Richard Trieu7eb0b2c2014-02-26 01:17:28 +000013
Richard Trieubeffb832014-04-15 23:47:53 +000014void test(long long ll, double d, int i, float f) {
15 // Suggest including cmath
Richard Trieu7eb0b2c2014-02-26 01:17:28 +000016 (void)abs(d);
17 // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}}
Richard Trieubeffb832014-04-15 23:47:53 +000018 // expected-note@-2{{use function 'std::abs' instead}}
Alp Toker5d96e0a2014-07-11 20:53:51 +000019 // expected-note@-3{{include the header <cmath> or explicitly provide a declaration for 'std::abs'}}
Richard Trieubeffb832014-04-15 23:47:53 +000020 // 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}}
Alp Toker5d96e0a2014-07-11 20:53:51 +000025 // expected-note@-3{{include the header <cmath> or explicitly provide a declaration for 'std::abs'}}
Richard Trieubeffb832014-04-15 23:47:53 +000026 // 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}}
Alp Toker5d96e0a2014-07-11 20:53:51 +000032 // expected-note@-3{{include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}}
Richard Trieubeffb832014-04-15 23:47:53 +000033 // 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}}
Alp Toker5d96e0a2014-07-11 20:53:51 +000037 // expected-note@-3{{include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}}
Richard Trieubeffb832014-04-15 23:47:53 +000038 // 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"
Richard Trieu7eb0b2c2014-02-26 01:17:28 +000053}