From 57a5c6b56c782d578d86cbf2e58bb403719afdee Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Mon, 16 Mar 2015 00:32:25 +0000 Subject: Move remove-cstr-calls from a standalone executable to a clang-tidy check readability-redundant-string-cstr http://reviews.llvm.org/D7318 Patch by Richard Thomson! llvm-svn: 232338 --- clang-tools-extra/test/CMakeLists.txt | 1 - .../readability-redundant-string-cstr.cpp | 42 ++++++++++++++++++++++ clang-tools-extra/test/remove-cstr-calls/basic.cpp | 39 -------------------- 3 files changed, 42 insertions(+), 40 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/readability-redundant-string-cstr.cpp delete mode 100644 clang-tools-extra/test/remove-cstr-calls/basic.cpp (limited to 'clang-tools-extra/test') diff --git a/clang-tools-extra/test/CMakeLists.txt b/clang-tools-extra/test/CMakeLists.txt index 298fa289385..8f0953122f7 100644 --- a/clang-tools-extra/test/CMakeLists.txt +++ b/clang-tools-extra/test/CMakeLists.txt @@ -42,7 +42,6 @@ set(CLANG_TOOLS_TEST_DEPS clang-tidy modularize pp-trace - remove-cstr-calls # Unit tests ExtraToolsUnitTests diff --git a/clang-tools-extra/test/clang-tidy/readability-redundant-string-cstr.cpp b/clang-tools-extra/test/clang-tidy/readability-redundant-string-cstr.cpp new file mode 100644 index 00000000000..42f4307b188 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/readability-redundant-string-cstr.cpp @@ -0,0 +1,42 @@ +// RUN: $(dirname %s)/check_clang_tidy.sh %s readability-redundant-string-cstr %t +// REQUIRES: shell + +namespace std { +template +class allocator {}; +template +class char_traits {}; +template +struct basic_string { + basic_string(); + basic_string(const C *p, const A &a = A()); + const C *c_str() const; +}; +typedef basic_string, std::allocator> string; +} +namespace llvm { +struct StringRef { + StringRef(const char *p); + StringRef(const std::string &); +}; +} + +void f1(const std::string &s) { + f1(s.c_str()); + // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to `c_str()` [readability-redundant-string-cstr] + // CHECK-FIXES: {{^ }}f1(s);{{$}} +} +void f2(const llvm::StringRef r) { + std::string s; + f2(s.c_str()); + // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call {{.*}} + // CHECK-FIXES: {{^ }}std::string s;{{$}} + // CHECK-FIXES-NEXT: {{^ }}f2(s);{{$}} +} +void f3(const llvm::StringRef &r) { + std::string s; + f3(s.c_str()); + // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call {{.*}} + // CHECK-FIXES: {{^ }}std::string s;{{$}} + // CHECK-FIXES-NEXT: {{^ }}f3(s);{{$}} +} diff --git a/clang-tools-extra/test/remove-cstr-calls/basic.cpp b/clang-tools-extra/test/remove-cstr-calls/basic.cpp deleted file mode 100644 index b63488db9f6..00000000000 --- a/clang-tools-extra/test/remove-cstr-calls/basic.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: remove-cstr-calls . %t.cpp -- -// RUN: FileCheck -input-file=%t.cpp %s -// REQUIRES: shell - -namespace std { -template class allocator {}; -template class char_traits {}; -template struct basic_string { - basic_string(); - basic_string(const C *p, const A& a = A()); - const C *c_str() const; -}; -typedef basic_string, std::allocator > string; -} -namespace llvm { -struct StringRef { - StringRef(const char *p); - StringRef(const std::string &); -}; -} - -void f1(const std::string &s) { - f1(s.c_str()); - // CHECK: void f1 - // CHECK-NEXT: f1(s) -} -void f2(const llvm::StringRef r) { - std::string s; - f2(s.c_str()); - // CHECK: std::string s; - // CHECK-NEXT: f2(s) -} -void f3(const llvm::StringRef &r) { - std::string s; - f3(s.c_str()); - // CHECK: std::string s; - // CHECK: f3(s) -} -- cgit v1.2.1