[PATCH] D18475: [clang-tidy] Add more detection rules for redundant c_str calls.

Etienne Bergeron via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 25 09:59:00 PDT 2016

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";

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.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18475.51647.patch
Type: text/x-patch
Size: 8717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160325/252afd3c/attachment-0001.bin>

More information about the cfe-commits mailing list