Etienne Bergeron | 1329b98 | 2016-03-22 17:39:36 +0000 | [diff] [blame^] | 1 | // RUN: %check_clang_tidy %s readability-redundant-string-init %t |
| 2 | |
| 3 | namespace std { |
| 4 | template <typename T> |
| 5 | class allocator {}; |
| 6 | template <typename T> |
| 7 | class char_traits {}; |
| 8 | template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C>> |
| 9 | struct basic_string { |
| 10 | basic_string(); |
| 11 | basic_string(const basic_string&); |
| 12 | // MSVC headers define two constructors instead of using optional arguments. |
| 13 | basic_string(const C *); |
| 14 | basic_string(const C *, const A &); |
| 15 | ~basic_string(); |
| 16 | }; |
| 17 | typedef basic_string<char> string; |
| 18 | typedef basic_string<wchar_t> wstring; |
| 19 | } |
| 20 | |
| 21 | void f() { |
| 22 | std::string a = ""; |
| 23 | // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization [readability-redundant-string-init] |
| 24 | // CHECK-FIXES: std::string a; |
| 25 | std::string b(""); |
| 26 | // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization |
| 27 | // CHECK-FIXES: std::string b; |
| 28 | std::string c = R"()"; |
| 29 | // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization |
| 30 | // CHECK-FIXES: std::string c; |
| 31 | std::string d(R"()"); |
| 32 | // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization |
| 33 | // CHECK-FIXES: std::string d; |
| 34 | |
| 35 | std::string u = "u"; |
| 36 | std::string w("w"); |
| 37 | std::string x = R"(x)"; |
| 38 | std::string y(R"(y)"); |
| 39 | std::string z; |
| 40 | } |
| 41 | |
| 42 | void g() { |
| 43 | std::wstring a = L""; |
| 44 | // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization |
| 45 | // CHECK-FIXES: std::wstring a; |
| 46 | std::wstring b(L""); |
| 47 | // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization |
| 48 | // CHECK-FIXES: std::wstring b; |
| 49 | std::wstring c = LR"()"; |
| 50 | // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization |
| 51 | // CHECK-FIXES: std::wstring c; |
| 52 | std::wstring d(LR"()"); |
| 53 | // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization |
| 54 | // CHECK-FIXES: std::wstring d; |
| 55 | |
| 56 | std::wstring u = L"u"; |
| 57 | std::wstring w(L"w"); |
| 58 | std::wstring x = LR"(x)"; |
| 59 | std::wstring y(LR"(y)"); |
| 60 | std::wstring z; |
| 61 | } |
| 62 | // RUN: %check_clang_tidy %s readability-redundant-string-init %t |
| 63 | |
| 64 | namespace std { |
| 65 | template <typename T> |
| 66 | class allocator {}; |
| 67 | template <typename T> |
| 68 | class char_traits {}; |
| 69 | template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C>> |
| 70 | struct basic_string { |
| 71 | basic_string(); |
| 72 | basic_string(const basic_string&); |
| 73 | // MSVC headers define two constructors instead of using optional arguments. |
| 74 | basic_string(const C *); |
| 75 | basic_string(const C *, const A &); |
| 76 | ~basic_string(); |
| 77 | }; |
| 78 | typedef basic_string<char> string; |
| 79 | typedef basic_string<wchar_t> wstring; |
| 80 | } |
| 81 | |
| 82 | void f() { |
| 83 | std::string a = ""; |
| 84 | // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization [readability-redundant-string-init] |
| 85 | // CHECK-FIXES: std::string a; |
| 86 | std::string b(""); |
| 87 | // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization |
| 88 | // CHECK-FIXES: std::string b; |
| 89 | std::string c = R"()"; |
| 90 | // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization |
| 91 | // CHECK-FIXES: std::string c; |
| 92 | std::string d(R"()"); |
| 93 | // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization |
| 94 | // CHECK-FIXES: std::string d; |
| 95 | |
| 96 | std::string u = "u"; |
| 97 | std::string w("w"); |
| 98 | std::string x = R"(x)"; |
| 99 | std::string y(R"(y)"); |
| 100 | std::string z; |
| 101 | } |
| 102 | |
| 103 | void g() { |
| 104 | std::wstring a = L""; |
| 105 | // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization |
| 106 | // CHECK-FIXES: std::wstring a; |
| 107 | std::wstring b(L""); |
| 108 | // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization |
| 109 | // CHECK-FIXES: std::wstring b; |
| 110 | std::wstring c = LR"()"; |
| 111 | // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization |
| 112 | // CHECK-FIXES: std::wstring c; |
| 113 | std::wstring d(LR"()"); |
| 114 | // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization |
| 115 | // CHECK-FIXES: std::wstring d; |
| 116 | |
| 117 | std::wstring u = L"u"; |
| 118 | std::wstring w(L"w"); |
| 119 | std::wstring x = LR"(x)"; |
| 120 | std::wstring y(LR"(y)"); |
| 121 | std::wstring z; |
| 122 | } |