1 // RUN: %check_clang_tidy %s bugprone-swapped-arguments %t
2
3 void F(int, double);
4
5 int SomeFunction();
6
7 template <typename T, typename U>
G(T a,U b)8 void G(T a, U b) {
9 F(a, b); // no-warning
10 F(2.0, 4);
11 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.
12 // CHECK-FIXES: F(4, 2.0)
13 }
14
foo()15 void foo() {
16 F(1.0, 3);
17 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.
18 // CHECK-FIXES: F(3, 1.0)
19
20 #define M(x, y) x##y()
21
22 double b = 1.0;
23 F(b, M(Some, Function));
24 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.
25 // CHECK-FIXES: F(M(Some, Function), b);
26
27 #define N F(b, SomeFunction())
28
29 N;
30 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.
31 // In macro, don't emit fixits.
32 // CHECK-FIXES: #define N F(b, SomeFunction())
33
34 G(b, 3);
35 G(3, 1.0);
36 G(0, 0);
37
38 F(1.0, 1.0); // no-warning
39 F(3, 1.0); // no-warning
40 F(true, false); // no-warning
41 F(0, 'c'); // no-warning
42
43 #define APPLY(f, x, y) f(x, y)
44 APPLY(F, 1.0, 3);
45 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.
46 // CHECK-FIXES: APPLY(F, 3, 1.0);
47
48 #define PARAMS 1.0, 3
49 #define CALL(P) F(P)
50 CALL(PARAMS);
51 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.
52 // In macro, don't emit fixits.
53 }
54