This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Support readability-redundant-string-cstr.StringParameterFunctions option
ClosedPublic

Authored by mikecrowe on Mar 12 2023, 1:44 PM.

Details

Summary

Add StringParameterFunctions option to allow the
readability-redundant-string-cstr check to work with library functions
such as fmt::format and spdlog::logger:info that are able to support
std::string arguments in addition to const char * ones.

Depends on D143342

Diff Detail

Event Timeline

mikecrowe created this revision.Mar 12 2023, 1:44 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: xazax.hun. · View Herald Transcript
mikecrowe requested review of this revision.Mar 12 2023, 1:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2023, 1:44 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I can squash this with https://reviews.llvm.org/D143342 if required.

PiotrZSL added inline comments.Mar 12 2023, 2:06 PM
clang-tools-extra/docs/ReleaseNotes.rst
152–154

`std::print, std::format or other functions listed in StringParameterFunction` check option.

clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst
14–30

too much noise in this, configuration example is not needed.
reference to C++20 or std::format/std::print also...

Strongly consider something like:
"A semicolon-separated list of (fully qualified) function/method/operator names, with the requirement that
any parameter currently accepting a 'const char*' input should also be able to accept 'std::string' inputs,
or proper overload candidates that can do so should exist. This can be used to configure functions such as fmt::format, spdlog::logger::info, or wrappers around these and similar functions. Default value is empty string."

PiotrZSL requested changes to this revision.Mar 12 2023, 2:30 PM

My only complain is documentation, changes in code and tests are correct.
Build failed mainly due to conflicts in previous change.
It should get green once prev patch will land, and this will be re-based.

I strongly suggest using arc (less issues with patches).

This revision now requires changes to proceed.Mar 12 2023, 2:30 PM

My only complain is documentation, changes in code and tests are correct.
Build failed mainly due to conflicts in previous change.
It should get green once prev patch will land, and this will be re-based.

Thanks for the comments. I will address them. I've rebased this change on top of the rebase of the previous one. Maybe that will help. Git didn't report any conflicts when I rebased.

I strongly suggest using arc (less issues with patches).

I have been using arc. I couldn't find a way to make it submit updates to more than one change at a time. I've done these two with git checkout HEAD~1 ; arc diff ; git checkout mybranch; arc diff. Is there a better way?

mikecrowe marked 2 inline comments as done.

Documentation updates suggested by @PiotrZSL. Rebase.

mikecrowe edited the summary of this revision. (Show Details)Mar 13 2023, 12:01 AM
PiotrZSL added inline comments.Mar 13 2023, 12:26 AM
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst
18

Put function names in double `, like fmt::format, spdlog::logger::info`

mikecrowe updated this revision to Diff 504537.Mar 13 2023, 1:15 AM
mikecrowe edited the summary of this revision. (Show Details)

Quote types and functions correctly in redundant-string-cstr.rst.

mikecrowe marked an inline comment as done.Mar 13 2023, 1:15 AM
This revision is now accepted and ready to land.Mar 13 2023, 1:24 AM