Richard Trieu | 7eb0b2c | 2014-02-26 01:17:28 +0000 | [diff] [blame] | 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 | |
Richard Trieu | beffb83 | 2014-04-15 23:47:53 +0000 | [diff] [blame] | 4 | extern "C" { |
| 5 | int abs(int); |
| 6 | float fabsf(float); |
| 7 | } |
Richard Trieu | 7eb0b2c | 2014-02-26 01:17:28 +0000 | [diff] [blame] | 8 | |
Richard Trieu | beffb83 | 2014-04-15 23:47:53 +0000 | [diff] [blame] | 9 | namespace std { |
| 10 | int abs(int); |
| 11 | float abs(float); |
| 12 | } |
Richard Trieu | 7eb0b2c | 2014-02-26 01:17:28 +0000 | [diff] [blame] | 13 | |
Richard Trieu | beffb83 | 2014-04-15 23:47:53 +0000 | [diff] [blame] | 14 | void test(long long ll, double d, int i, float f) { |
| 15 | // Suggest including cmath |
Richard Trieu | 7eb0b2c | 2014-02-26 01:17:28 +0000 | [diff] [blame] | 16 | (void)abs(d); |
| 17 | // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} |
Richard Trieu | beffb83 | 2014-04-15 23:47:53 +0000 | [diff] [blame] | 18 | // expected-note@-2{{use function 'std::abs' instead}} |
Alp Toker | 5d96e0a | 2014-07-11 20:53:51 +0000 | [diff] [blame] | 19 | // expected-note@-3{{include the header <cmath> or explicitly provide a declaration for 'std::abs'}} |
Richard Trieu | beffb83 | 2014-04-15 23:47:53 +0000 | [diff] [blame] | 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}} |
Alp Toker | 5d96e0a | 2014-07-11 20:53:51 +0000 | [diff] [blame] | 25 | // expected-note@-3{{include the header <cmath> or explicitly provide a declaration for 'std::abs'}} |
Richard Trieu | beffb83 | 2014-04-15 23:47:53 +0000 | [diff] [blame] | 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}} |
Alp Toker | 5d96e0a | 2014-07-11 20:53:51 +0000 | [diff] [blame] | 32 | // expected-note@-3{{include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}} |
Richard Trieu | beffb83 | 2014-04-15 23:47:53 +0000 | [diff] [blame] | 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}} |
Alp Toker | 5d96e0a | 2014-07-11 20:53:51 +0000 | [diff] [blame] | 37 | // expected-note@-3{{include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}} |
Richard Trieu | beffb83 | 2014-04-15 23:47:53 +0000 | [diff] [blame] | 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" |
Richard Trieu | 7eb0b2c | 2014-02-26 01:17:28 +0000 | [diff] [blame] | 53 | } |