This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Handle data() in readability-redundant-string-cstr
ClosedPublic

Authored by malcolm.parsons on Nov 3 2016, 5:27 AM.

Details

Summary

std::string::data() and std::string::c_str() are equivalent.
Enhance the readability-redundant-string-cstr check to also handle
calls to data().

Event Timeline

malcolm.parsons retitled this revision from to [clang-tidy] Handle data() in readability-redundant-string-cstr.
malcolm.parsons updated this object.
malcolm.parsons added a subscriber: cfe-commits.
aaron.ballman accepted this revision.Nov 3 2016, 5:38 AM
aaron.ballman edited edge metadata.

LGTM!

I like the idea, but would point out that data() and c_str() had different semantics once upon a time. In c++03 and earlier, data() was not guaranteed to be null terminated, but`c_str()` was. However, I'm not certain that's worth altering the behavior of this check for; I don't think any implementation actually made that distinction in practice.

This revision is now accepted and ready to land.Nov 3 2016, 5:38 AM

I like the idea, but would point out that data() and c_str() had different semantics once upon a time.

I'm aware of this, but it doesn't affect whether the call is redundant.

malcolm.parsons edited edge metadata.

Add to release notes.
Add to documentation of check.

This revision was automatically updated to reflect the committed changes.