diff options
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp')
| -rw-r--r-- | clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp index 76d1fe97e1b..eb77d9f195b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp @@ -1,4 +1,9 @@ -// RUN: %check_clang_tidy %s readability-redundant-string-init %t +// RUN: %check_clang_tidy -std=c++11,c++14 %s readability-redundant-string-init %t \ +// RUN: -config="{CheckOptions: \ +// RUN: [{key: readability-redundant-string-init.StringNames, \ +// RUN: value: "::std::basic_string;our::TestString"}] \ +// RUN: }" +// FIXME: Fix the checker to work in C++17 mode. namespace std { template <typename T> @@ -143,3 +148,82 @@ extern void Param2(const std::string& param = ""); void Param3(std::string param = "") {} void Param4(STRING param = "") {} +namespace our { +struct TestString { + TestString(); + TestString(const TestString &); + TestString(const char *); + ~TestString(); +}; +} + +void ourTestStringTests() { + our::TestString a = ""; + // CHECK-MESSAGES: [[@LINE-1]]:19: warning: redundant string initialization + // CHECK-FIXES: our::TestString a; + our::TestString b(""); + // CHECK-MESSAGES: [[@LINE-1]]:19: warning: redundant string initialization + // CHECK-FIXES: our::TestString b; + our::TestString c = R"()"; + // CHECK-MESSAGES: [[@LINE-1]]:19: warning: redundant string initialization + // CHECK-FIXES: our::TestString c; + our::TestString d(R"()"); + // CHECK-MESSAGES: [[@LINE-1]]:19: warning: redundant string initialization + // CHECK-FIXES: our::TestString d; + + our::TestString u = "u"; + our::TestString w("w"); + our::TestString x = R"(x)"; + our::TestString y(R"(y)"); + our::TestString z; +} + +namespace their { +using TestString = our::TestString; +} + +// their::TestString is the same type so should warn / fix +void theirTestStringTests() { + their::TestString a = ""; + // CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization + // CHECK-FIXES: their::TestString a; + their::TestString b(""); + // CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization + // CHECK-FIXES: their::TestString b; +} + +namespace other { +// Identical declarations to above but different type +struct TestString { + TestString(); + TestString(const TestString &); + TestString(const char *); + ~TestString(); +}; + +// Identical declarations to above but different type +template <typename T> +class allocator {}; +template <typename T> +class char_traits {}; +template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C>> +struct basic_string { + basic_string(); + basic_string(const basic_string &); + basic_string(const C *, const A &a = A()); + ~basic_string(); +}; +typedef basic_string<char> string; +typedef basic_string<wchar_t> wstring; +} + +// other::TestString, other::string, other::wstring are unrelated to the types +// being checked. No warnings / fixes should be produced for these types. +void otherTestStringTests() { + other::TestString a = ""; + other::TestString b(""); + other::string c = ""; + other::string d(""); + other::wstring e = L""; + other::wstring f(L""); +} |

