summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/readability-redundant-string-cstr.cpp
diff options
context:
space:
mode:
authorMalcolm Parsons <malcolm.parsons@gmail.com>2016-11-03 12:56:48 +0000
committerMalcolm Parsons <malcolm.parsons@gmail.com>2016-11-03 12:56:48 +0000
commit8b70e2631c6ab4259a4aa9e797c99132fb66e79b (patch)
tree2f6c75fc3c1c324c2d6f2def8d14a9c97e25279c /clang-tools-extra/test/clang-tidy/readability-redundant-string-cstr.cpp
parenta705ab175d2b6b6ae0edb234b49a76fe6db38144 (diff)
downloadbcm5719-llvm-8b70e2631c6ab4259a4aa9e797c99132fb66e79b.tar.gz
bcm5719-llvm-8b70e2631c6ab4259a4aa9e797c99132fb66e79b.zip
[clang-tidy] Handle data() in readability-redundant-string-cstr
Summary: std::string::data() and std::string::c_str() are equivalent. Enhance the readability-redundant-string-cstr check to also handle calls to data(). Reviewers: etienneb, alexfh, aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D26279 llvm-svn: 285901
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/readability-redundant-string-cstr.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/readability-redundant-string-cstr.cpp14
1 files changed, 9 insertions, 5 deletions
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
index 009168f1550..976a54f7f3a 100644
--- a/clang-tools-extra/test/clang-tidy/readability-redundant-string-cstr.cpp
+++ b/clang-tools-extra/test/clang-tidy/readability-redundant-string-cstr.cpp
@@ -16,6 +16,7 @@ struct basic_string {
basic_string(const C *p, const A &a = A());
const C *c_str() const;
+ const C *data() const;
_Type& append(const C *s);
_Type& append(const C *s, size n);
@@ -66,7 +67,10 @@ struct StringRef {
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-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+ // CHECK-FIXES: {{^ }}f1(s);{{$}}
+ f1(s.data());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
// CHECK-FIXES: {{^ }}f1(s);{{$}}
}
void f2(const llvm::StringRef r) {
@@ -86,7 +90,7 @@ void f3(const llvm::StringRef &r) {
void f4(const std::string &s) {
const std::string* ptr = &s;
f1(ptr->c_str());
- // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to `c_str()` [readability-redundant-string-cstr]
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
// CHECK-FIXES: {{^ }}f1(*ptr);{{$}}
}
void f5(const std::string &s) {
@@ -168,7 +172,7 @@ void f6(const std::string &s) {
void g1(const std::wstring &s) {
g1(s.c_str());
- // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to `c_str()` [readability-redundant-string-cstr]
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
// CHECK-FIXES: {{^ }}g1(s);{{$}}
}
@@ -176,7 +180,7 @@ void g1(const std::wstring &s) {
void h1(const std::u16string &s) {
h1(s.c_str());
- // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to `c_str()` [readability-redundant-string-cstr]
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
// CHECK-FIXES: {{^ }}h1(s);{{$}}
}
@@ -184,7 +188,7 @@ void h1(const std::u16string &s) {
void k1(const std::u32string &s) {
k1(s.c_str());
- // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to `c_str()` [readability-redundant-string-cstr]
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
// CHECK-FIXES: {{^ }}k1(s);{{$}}
}
OpenPOWER on IntegriCloud