summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clang-tidy] Cleaning namespaces to be more consistant across checkers.Etienne Bergeron2016-05-021-5/+4
| | | | | | | | | | | | | | Summary: The goal of the patch is to bring checkers in their appropriate namespace. This path doesn't change any behavior. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D19811 llvm-svn: 268264
* [clang-tidy] Add more detection rules for redundant c_str calls.Etienne Bergeron2016-04-151-2/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The string class contains methods which support receiving either a string literal or a string object. For example, calls to append can receive either a char* or a string. ``` string& append (const string& str); string& append (const char* s); ``` Which make these cases equivalent, and the .c_str() useless: ``` std::string s = "123"; str.append(s); str.append(s.c_str()); ``` In these cases, removing .c_str() doesn't provide any size or speed improvement. It's only a readability issue. If the string contains embedded NUL characters, the string literal and the string object won't produce the same semantic. Reviewers: alexfh, sbenza Subscribers: LegalizeAdulthood, aaron.ballman, chapuni, Eugene.Zelenko, cfe-commits Differential Revision: http://reviews.llvm.org/D18475 llvm-svn: 266463
* [clang-tidy] Add support for different char-types for the ↵Etienne Bergeron2016-03-241-14/+14
| | | | | | | | | | | | | | | | | | | | | readability-redundant-string-cstr checker. Summary: The current checker is able to recognize std::string but does not recognize other string variants. This patch is adding the support for any string defined with basic_string without considering the the underlying char type. The most common variant is: 'std::wstring' based on 'wchar_t'. There are also other string variants added to the standard: u16string, u32string, etc... Reviewers: alexfh Subscribers: mamai, dblaikie, cfe-commits Differential Revision: http://reviews.llvm.org/D18412 llvm-svn: 264325
* [clang-tidy] Fix redundant-string-cstr check with msvc 14 headers.Etienne Bergeron2016-03-221-19/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The string constructors are not defined using optional parameters and are not recognize by the checker. The constructor defined in the MSVC header is defined with 1 parameter. Therefore, patterns are not recognized by the checker. The current patch add support to accept constructor with only one parameter. Repro on a Visual Studio 14 installation with the following code: ``` void f1(const std::string &s) { f1(s.c_str()); } ``` In the xstring.h header, the constructors are defined this way: ``` basic_string(const _Myt& _Right) [...] basic_string(const _Myt& _Right, const _Alloc& _Al) [...] ``` The CXXConstructExpr to recognize only contains 1 parameter. ``` CXXConstructExpr 0x3f1a070 <C:\src\llvm\examples\test.cc:6:6, col:14> 'const std::string':'const class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char> >' 'void (const char *) __attribute__((thiscall))' `-CXXMemberCallExpr 0x3f1a008 <col:6, col:14> 'const char *' `-MemberExpr 0x3f19fe0 <col:6, col:8> '<bound member function type>' .c_str 0x3cc22f8 `-DeclRefExpr 0x3f19fc8 <col:6> 'const std::string':'const class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char> >' lvalue ParmVar 0x3f19c80 's' 'const std::string &' ``` Reviewers: aaron.ballman, alexfh Subscribers: aemerson Differential Revision: http://reviews.llvm.org/D18285 llvm-svn: 264075
* Refactors AST matching code to use the new AST matcher names. This patch ↵Aaron Ballman2015-09-171-14/+16
| | | | | | correlates to r247885 which performs the AST matcher rename in Clang. llvm-svn: 247886
* Disable clang-tidy readability checkers when not compiling in C++ mode. None ↵Aaron Ballman2015-09-021-0/+5
| | | | | | of the checkers require additional testing as the tests will not compile for other languages or modes, or the checkers would never match a valid construct. llvm-svn: 246661
* Move remove-cstr-calls from a standalone executable to a clang-tidy check ↵Alexander Kornienko2015-03-161-0/+138
readability-redundant-string-cstr http://reviews.llvm.org/D7318 Patch by Richard Thomson! llvm-svn: 232338
OpenPOWER on IntegriCloud