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 f()21void 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 g()42void 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