Manuel Klimek | b91bee0 | 2015-10-22 11:31:44 +0000 | [diff] [blame] | 1 | // RUN: %check_clang_tidy %s google-build-explicit-make-pair %t |
Benjamin Kramer | 47c4d10 | 2014-07-15 09:50:32 +0000 | [diff] [blame] | 2 | |
| 3 | namespace std { |
| 4 | template <class T1, class T2> |
| 5 | struct pair { |
| 6 | pair(T1 x, T2 y) {} |
| 7 | }; |
| 8 | |
| 9 | template <class T1, class T2> |
| 10 | pair<T1, T2> make_pair(T1 x, T2 y) { |
| 11 | return pair<T1, T2>(x, y); |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | template <typename T> |
| 16 | void templ(T a, T b) { |
| 17 | std::make_pair<T, unsigned>(a, b); |
Benjamin Kramer | 2b584f3 | 2014-07-15 13:11:49 +0000 | [diff] [blame] | 18 | 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 Kramer | 47c4d10 | 2014-07-15 09:50:32 +0000 | [diff] [blame] | 21 | } |
| 22 | |
Benjamin Kramer | ddf36de | 2014-07-21 09:40:52 +0000 | [diff] [blame] | 23 | template <typename T> |
| 24 | int t(); |
| 25 | |
Benjamin Kramer | 47c4d10 | 2014-07-15 09:50:32 +0000 | [diff] [blame] | 26 | void 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); |
| 40 | M |
| 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 Kramer | 2b584f3 | 2014-07-15 13:11:49 +0000 | [diff] [blame] | 47 | templ(1U, 2U); |
Benjamin Kramer | 47c4d10 | 2014-07-15 09:50:32 +0000 | [diff] [blame] | 48 | |
| 49 | std::make_pair(i, 1); // no-warning |
Benjamin Kramer | ddf36de | 2014-07-21 09:40:52 +0000 | [diff] [blame] | 50 | std::make_pair(t<int>, 1); |
Benjamin Kramer | 47c4d10 | 2014-07-15 09:50:32 +0000 | [diff] [blame] | 51 | } |