blob: 6dcd357f511315f32f2b0ee78f22834af0fc9679 [file] [log] [blame]
Manuel Klimekb91bee02015-10-22 11:31:44 +00001// RUN: %check_clang_tidy %s google-build-explicit-make-pair %t
Benjamin Kramer47c4d102014-07-15 09:50:32 +00002
3namespace std {
4template <class T1, class T2>
5struct pair {
6 pair(T1 x, T2 y) {}
7};
8
9template <class T1, class T2>
10pair<T1, T2> make_pair(T1 x, T2 y) {
11 return pair<T1, T2>(x, y);
12}
13}
14
15template <typename T>
16void templ(T a, T b) {
17 std::make_pair<T, unsigned>(a, b);
Benjamin Kramer2b584f32014-07-15 13:11:49 +000018 std::make_pair<int, int>(1, 2);
19// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, omit template arguments from make_pair
20// CHECK-FIXES: std::make_pair(1, 2)
Benjamin Kramer47c4d102014-07-15 09:50:32 +000021}
22
Benjamin Kramerddf36de2014-07-21 09:40:52 +000023template <typename T>
24int t();
25
Benjamin Kramer47c4d102014-07-15 09:50:32 +000026void test(int i) {
27 std::make_pair<int, int>(i, i);
28// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, omit template arguments from make_pair
29// CHECK-FIXES: std::make_pair(i, i)
30
31 std::make_pair<unsigned, int>(i, i);
32// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, use pair directly
33// CHECK-FIXES: std::pair<unsigned, int>(i, i)
34
35 std::make_pair<int, unsigned>(i, i);
36// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, use pair directly
37// CHECK-FIXES: std::pair<int, unsigned>(i, i)
38
39#define M std::make_pair<int, unsigned>(i, i);
40M
41// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: for C++11-compatibility, use pair directly
42// Can't fix in macros.
43// CHECK-FIXES: #define M std::make_pair<int, unsigned>(i, i);
44// CHECK-FIXES-NEXT: M
45
46 templ(i, i);
Benjamin Kramer2b584f32014-07-15 13:11:49 +000047 templ(1U, 2U);
Benjamin Kramer47c4d102014-07-15 09:50:32 +000048
49 std::make_pair(i, 1); // no-warning
Benjamin Kramerddf36de2014-07-21 09:40:52 +000050 std::make_pair(t<int>, 1);
Benjamin Kramer47c4d102014-07-15 09:50:32 +000051}