| 1 |
// RUN: %check_clang_tidy %s google-build-explicit-make-pair %t |
| 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); |
| 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) |
| 21 |
} |
| 22 |
|
| 23 |
template <typename T> |
| 24 |
int t(); |
| 25 |
|
| 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); |
| 47 |
templ(1U, 2U); |
| 48 |
|
| 49 |
std::make_pair(i, 1); // no-warning |
| 50 |
std::make_pair(t<int>, 1); |
| 51 |
} |