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