This is an archive of the discontinued LLVM Phabricator instance.

Add a new check, readability-redundant-string-init, that checks unnecessary string initializations.
ClosedPublic

Authored by shuaiwang on Feb 24 2016, 5:46 PM.

Diff Detail

Event Timeline

shuaiwang updated this revision to Diff 48997.Feb 24 2016, 5:46 PM
shuaiwang retitled this revision from to Add a new check, readability-redundant-string-init, that checks unnecessary string initializations..
shuaiwang added a subscriber: cfe-commits.
hokein accepted this revision.Feb 25 2016, 6:17 AM
hokein edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Feb 25 2016, 6:17 AM
alexfh added inline comments.Feb 25 2016, 7:27 AM
clang-tidy/readability/RedundantStringInitCheck.cpp
26

nit: ast_matchers:: can be omitted.

54

ditto

test/clang-tidy/readability-redundant-string-init.cpp
1

Please add test cases with:

  • a template with multiple instantiations
  • macros, something along the lines of:
#define M(x) x
M({ std::string a = ""; })
#define M2 { std::string b = ""; }
M2;
M2;
shuaiwang updated this revision to Diff 49108.Feb 25 2016, 12:50 PM
shuaiwang edited edge metadata.

more test cases

shuaiwang marked 3 inline comments as done.Feb 25 2016, 12:54 PM
alexfh added inline comments.Feb 25 2016, 3:11 PM
test/clang-tidy/readability-redundant-string-init.cpp
70

Please add a CHECK-FIXES to ensure the macro definition hasn't changed and that the macro invocations below are intact.

shuaiwang updated this revision to Diff 49114.Feb 25 2016, 3:15 PM

CHECK-FIXES for macro tests

shuaiwang marked an inline comment as done.Feb 25 2016, 3:16 PM
alexfh accepted this revision.Feb 25 2016, 3:33 PM
alexfh edited edge metadata.

Looks good!

I'll commit the patch for you.

This revision was automatically updated to reflect the committed changes.

Sorry for arriving late to party :-)

Thank you for great check! I found a quite lot of such problems in my code base, but I'd like to make suggestion for further improvements: PR26756.

Sorry for arriving late to party :-)

Thank you for great check! I found a quite lot of such problems in my code base, but I'd like to make suggestion for further improvements: PR26756.

The full link is: http://llvm.org/PR26756

alexfh added a comment.Apr 5 2016, 6:28 AM

Shuai, if you have time, could you take a look at http://llvm.org/PR27087?

Thanks!