[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 10:24:05 PDT 2016
etienneb added a comment.
In http://reviews.llvm.org/D18475#383520, @Eugene.Zelenko wrote:
> Thank you for enhancement!
> I think will be good idea to extend check for any function call that receives .c_str(), since it mat be in other classes could have methods which receives both C++ or C strings. See also PR24870.
I was thinking the same when I started that patch. But, there is multiple cases where it will bring a false-positive.
As an example:
string& insert (size_t pos, const string& str, size_t subpos, size_t sublen = npos);
string& insert (size_t pos, const char* s, size_t n);
Even if the overloaded name/types are compatible, the semantic is not the same. You can't simply remove the .c_str() here.
I agree that a more general cases could exists, but I would like to be able to turn it off over a large code base when trying to keep false positives as low as posible.
More information about the cfe-commits