This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls
ClosedPublic

Authored by kuhar on Apr 30 2017, 3:43 PM.

Details

Summary

This patch makes modernize-use-emplace remove unnecessary make_ calls from push_back calls and turn them into emplace_back -- the same way make_pair calls are handled.
Custom make_ calls can be removed for custom tuple-like types -- two new options that control that are TupleTypes and TupleMakeFunctions. By default, the check removes calls to std::make_pair and std::make_tuple.

Eq.

std::vector<std::tuple<int, char, bool>> v;
v.push_back(std::make_tuple(1, 'A', true)); // --> v.emplace_back(1, 'A', true);

Diff Detail

Repository
rL LLVM

Event Timeline

kuhar created this revision.Apr 30 2017, 3:43 PM
kuhar updated this revision to Diff 97248.Apr 30 2017, 3:56 PM

Cosmetic changes.

JonasToth edited edge metadata.Apr 30 2017, 4:52 PM

Nothing to complain from my side.
Would it make sense to add boost pairs/tuples support?
I could imagine modernize checks that would transform boost structures into the stl ones, but that's another discussion probably.

Something for a later check: the same logic should apply for insert and emplace, we should add support for these methods too.

kuhar added a comment.Apr 30 2017, 5:01 PM

Would it make sense to add boost pairs/tuples support?

I think it can be added the same way it is possible to specify smart pointers and vector-like containers now. It would require users to provide both types and make functions (eg. thingy and make_thingy). I'm not sure if that would be any useful in practise, though.

Something for a later check: the same logic should apply for insert and emplace, we should add support for these methods too.

Yeah, I plan to do that a few patches from now, after other things are improved.

kuhar updated this revision to Diff 97299.May 1 2017, 9:25 AM
kuhar edited the summary of this revision. (Show Details)

I went ahead and generalized the patch to support custom tuple-like types and custom make_ functions.
I added a bunch of tests and updated the docs.

Let me know what you think.

i like the generalization.

clang-tidy/modernize/UseEmplaceCheck.cpp
115 ↗(On Diff #97299)

i think this); should move up a line. clang-format seems to make this all the time.

JonasToth added a subscriber: JonasToth.
kuhar updated this revision to Diff 98073.May 6 2017, 10:26 AM

I updated the patch against the current trunk.

I also run the modernize-use-emplace check on llvm and verified that there are no new regressions after applying fixits.

No comments from me either, looks good!

Prazek accepted this revision.May 14 2017, 9:01 AM

LGTM

This revision is now accepted and ready to land.May 14 2017, 9:01 AM
This revision was automatically updated to reflect the committed changes.
kuhar updated this revision to Diff 99103.May 15 2017, 10:46 PM

The patch broke the spinx docs build and I had to revert it in r303140.
I fixed the docs file problems.