This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix PR#44620 'readability-redundant-string-cstr quick-fix causes invalid code'
ClosedPublic

Authored by f00kat on Feb 5 2020, 2:55 AM.

Details

Summary
#include <string>

static void f2(std::string&&) {
}

static void f() {
	std::string const s;
	f2(s.c_str()); // readability-redundant-string-cstr warning
}

For this case I decide to do nothing by skipping it in the matcher. Another way is to fix with 'std::move(s)' but I`m not sure that it is correct.

Diff Detail

Event Timeline

f00kat created this revision.Feb 5 2020, 2:55 AM
aaron.ballman added inline comments.Feb 11 2020, 1:36 AM
clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
64

Missing a full stop at the end of the comment.

66

This function and the one below can be static.

83

Missing full stop at the end of the comment.

93

What if the call expression has no callee decl, like a call through a function pointer? This might have to be dyn_cast_or_null<> (That's probably a good test case to add.)

148

Missing a full stop at the end of the comment.

clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp
209–210

Missing full stop, can also remove the trailing newline.

f00kat updated this revision to Diff 243833.Feb 11 2020, 5:39 AM
  1. Add full stops at the end of the lines.
  2. Add some static.
  3. Fix function 'checkParamDeclOfAncestorCallExprHasRValueRefType' to work well with the function pointer calls.
aaron.ballman accepted this revision.Feb 18 2020, 11:33 AM

LGTM! Do you need me to commit on your behalf, or have you obtained git privileges recently?

This revision is now accepted and ready to land.Feb 18 2020, 11:33 AM

Yes, commit please. Thank you!

I've commit on your behalf in 47282b1b4bf3e18d2e2166b87159115ed520a2aa, thank you for the patch!