This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix readability-redundant-string-cstr for smart pointer #576705
ClosedPublic

Authored by mikecrowe on Mar 9 2023, 1:40 PM.

Details

Summary

Fix the readability-redundant-string-cstr check to correctly replace
calls to c_str() via an overloaded operator-> (such as from an
iterator.)

Previously, the fix for i->c_str() would be *i->. Using consume_back
to remove any trailing -> results in the correct *i.

Add some lit check test cases too.

Fixes: https://github.com/llvm/llvm-project/issues/56705

Diff Detail

Event Timeline

mikecrowe created this revision.Mar 9 2023, 1:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2023, 1:40 PM
mikecrowe requested review of this revision.Mar 9 2023, 1:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2023, 1:40 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
PiotrZSL accepted this revision.Mar 9 2023, 2:35 PM

Also consider reducing commit message, instead just copying issue description.
Simple description about issue would be sufficient.

No functional issues, so LGTM.

clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
56

You don't need to reference issue (it's already in commit message) here, better comment like "// Removing remaining '->' from overloaded operator call"

This revision is now accepted and ready to land.Mar 9 2023, 2:35 PM

Also consider reducing commit message, instead just copying issue description.
Simple description about issue would be sufficient.

TBH, I wasn't expecting this change to be accepted. I was merely hoping that it would cause someone to give me a hint as to how to fix it properly. That's why I included so much information in the commit message. I will shorten the commit message.

No functional issues, so LGTM.

Thanks for the review.

Code is correct, simply this check uses more manual string manipulation.
In theory there could be some more issues if operator -> wouldn't return pointer, but a class with additional operator ->, but that's legacy independent issue.

mikecrowe updated this revision to Diff 504108.Mar 10 2023, 5:30 AM
mikecrowe marked an inline comment as done.

Fix comment in code as suggested by PiotrZSL. Improve lit check tests.

mikecrowe retitled this revision from [clang-tidy] readability-redundant-string-cstr for smart pointer #576705 to [PATCH] [clang-tidy] Fix readability-redundant-string-cstr for smart pointer #576705.Mar 10 2023, 5:32 AM
mikecrowe edited the summary of this revision. (Show Details)
PiotrZSL accepted this revision.Mar 10 2023, 5:33 AM

Thanks for the speedy re-review. I don't have commit permission, so please can you land this if you are happy to do so?

PiotrZSL retitled this revision from [PATCH] [clang-tidy] Fix readability-redundant-string-cstr for smart pointer #576705 to [clang-tidy] Fix readability-redundant-string-cstr for smart pointer #576705.Mar 10 2023, 5:53 AM

Thanks, and sorry about the erroneous [PATCH] in the summary. :(