blob: 895b8e69bf50e38a44d86e6f7ddb432e295fb5d9 [file] [log] [blame]
Benjamin Kramer47c4d102014-07-15 09:50:32 +00001// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s google-build-explicit-make-pair %t
2// REQUIRES: shell
3
4namespace std {
5template <class T1, class T2>
6struct pair {
7 pair(T1 x, T2 y) {}
8};
9
10template <class T1, class T2>
11pair<T1, T2> make_pair(T1 x, T2 y) {
12 return pair<T1, T2>(x, y);
13}
14}
15
16template <typename T>
17void templ(T a, T b) {
18 std::make_pair<T, unsigned>(a, b);
Benjamin Kramer2b584f32014-07-15 13:11:49 +000019 std::make_pair<int, int>(1, 2);
20// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, omit template arguments from make_pair
21// CHECK-FIXES: std::make_pair(1, 2)
Benjamin Kramer47c4d102014-07-15 09:50:32 +000022}
23
Benjamin Kramerddf36de2014-07-21 09:40:52 +000024template <typename T>
25int t();
26
Benjamin Kramer47c4d102014-07-15 09:50:32 +000027void test(int i) {
28 std::make_pair<int, int>(i, i);
29// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, omit template arguments from make_pair
30// CHECK-FIXES: std::make_pair(i, i)
31
32 std::make_pair<unsigned, int>(i, i);
33// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, use pair directly
34// CHECK-FIXES: std::pair<unsigned, int>(i, i)
35
36 std::make_pair<int, unsigned>(i, i);
37// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, use pair directly
38// CHECK-FIXES: std::pair<int, unsigned>(i, i)
39
40#define M std::make_pair<int, unsigned>(i, i);
41M
42// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: for C++11-compatibility, use pair directly
43// Can't fix in macros.
44// CHECK-FIXES: #define M std::make_pair<int, unsigned>(i, i);
45// CHECK-FIXES-NEXT: M
46
47 templ(i, i);
Benjamin Kramer2b584f32014-07-15 13:11:49 +000048 templ(1U, 2U);
Benjamin Kramer47c4d102014-07-15 09:50:32 +000049
50 std::make_pair(i, 1); // no-warning
Benjamin Kramerddf36de2014-07-21 09:40:52 +000051 std::make_pair(t<int>, 1);
Benjamin Kramer47c4d102014-07-15 09:50:32 +000052}