[PATCH] D18475: [clang-tidy] Add more detection rules for redundant c_str calls.
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 25 10:12:07 PDT 2016
On Fri, Mar 25, 2016 at 9:59 AM, Etienne Bergeron via cfe-commits <
cfe-commits at lists.llvm.org> wrote:
> etienneb created this revision.
> etienneb added a subscriber: cfe-commits.
>
> 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.
>
potential speed improvement by not having to search for the null terminator
>
> If the string contains embedded NUL characters, the string literal and
> the string
> object won't produce the same semantic.
>
>
> http://reviews.llvm.org/D18475
>
> Files:
> clang-tidy/readability/RedundantStringCStrCheck.cpp
> test/clang-tidy/readability-redundant-string-cstr.cpp
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160325/b4b2749d/attachment-0001.html>
More information about the cfe-commits
mailing list