Benjamin Kramer | 47c4d10 | 2014-07-15 09:50:32 +0000 | [diff] [blame] | 1 | // RUN: $(dirname %s)/check_clang_tidy_fix.sh %s google-build-explicit-make-pair %t |
| 2 | // REQUIRES: shell |
| 3 | |
| 4 | namespace std { |
| 5 | template <class T1, class T2> |
| 6 | struct pair { |
| 7 | pair(T1 x, T2 y) {} |
| 8 | }; |
| 9 | |
| 10 | template <class T1, class T2> |
| 11 | pair<T1, T2> make_pair(T1 x, T2 y) { |
| 12 | return pair<T1, T2>(x, y); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | template <typename T> |
| 17 | void templ(T a, T b) { |
| 18 | std::make_pair<T, unsigned>(a, b); |
Benjamin Kramer | 2b584f3 | 2014-07-15 13:11:49 +0000 | [diff] [blame] | 19 | 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 Kramer | 47c4d10 | 2014-07-15 09:50:32 +0000 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | void test(int i) { |
| 25 | std::make_pair<int, int>(i, i); |
| 26 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, omit template arguments from make_pair |
| 27 | // CHECK-FIXES: std::make_pair(i, i) |
| 28 | |
| 29 | std::make_pair<unsigned, int>(i, i); |
| 30 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, use pair directly |
| 31 | // CHECK-FIXES: std::pair<unsigned, int>(i, i) |
| 32 | |
| 33 | std::make_pair<int, unsigned>(i, i); |
| 34 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, use pair directly |
| 35 | // CHECK-FIXES: std::pair<int, unsigned>(i, i) |
| 36 | |
| 37 | #define M std::make_pair<int, unsigned>(i, i); |
| 38 | M |
| 39 | // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: for C++11-compatibility, use pair directly |
| 40 | // Can't fix in macros. |
| 41 | // CHECK-FIXES: #define M std::make_pair<int, unsigned>(i, i); |
| 42 | // CHECK-FIXES-NEXT: M |
| 43 | |
| 44 | templ(i, i); |
Benjamin Kramer | 2b584f3 | 2014-07-15 13:11:49 +0000 | [diff] [blame] | 45 | templ(1U, 2U); |
Benjamin Kramer | 47c4d10 | 2014-07-15 09:50:32 +0000 | [diff] [blame] | 46 | |
| 47 | std::make_pair(i, 1); // no-warning |
| 48 | } |