This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Improve modernize-use-emplace check
ClosedPublic

Authored by joeywatts on Aug 10 2022, 2:51 PM.

Details

Summary

This patch improves the modernize-use-emplace check by adding support for
detecting inefficient invocations of the push and push_front methods on
STL-style containers and replacing them with their emplace-style equivalent.

Fixes #56996.

Diff Detail

Event Timeline

joeywatts created this revision.Aug 10 2022, 2:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2022, 2:51 PM
joeywatts updated this revision to Diff 451689.Aug 10 2022, 5:07 PM

Update documentation

Eugene.Zelenko retitled this revision from (wip) improve modernize-use-emplace check to [clang-tidy][wip] improve modernize-use-emplace check.Aug 10 2022, 10:19 PM
Eugene.Zelenko added a project: Restricted Project.

Please mention changes in Release Notes.

joeywatts updated this revision to Diff 451842.Aug 11 2022, 6:56 AM
joeywatts retitled this revision from [clang-tidy][wip] improve modernize-use-emplace check to [clang-tidy] Improve modernize-use-emplace check.
joeywatts edited the summary of this revision. (Show Details)

Updated commit title/description.

joeywatts updated this revision to Diff 451847.Aug 11 2022, 7:11 AM

Add changes to release notes.

joeywatts published this revision for review.Aug 11 2022, 7:14 AM
joeywatts updated this revision to Diff 451850.Aug 11 2022, 7:18 AM

Update commit title/message

Just a general drive by comment here and doesn't affect this patch.
This specifying containers logic is a little verbose, There may be a case to deprecate most of these options and just detect containers with an equivalent emplace* method at runtime.

clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
297–310
327
332
joeywatts added a comment.EditedAug 11 2022, 8:06 AM

Just a general drive by comment here and doesn't affect this patch.
This specifying containers logic is a little verbose, There may be a case to deprecate most of these options and just detect containers with an equivalent emplace* method at runtime.

I thought the same thing, but wasn't sure what the stance is on breaking changes here: would it be a problem if the existing "ContainersWithPush" option were removed in favor of a more generic option for a list of containers?

EDIT: ah, I see you mean not specifying any list of containers at all and just detecting if the type has an equivalent emplace-style method.

joeywatts updated this revision to Diff 451960.Aug 11 2022, 1:21 PM

Address code review comments

joeywatts marked 3 inline comments as done.Aug 11 2022, 1:23 PM
njames93 accepted this revision.Aug 17 2022, 12:35 PM
This revision is now accepted and ready to land.Aug 17 2022, 12:35 PM

Thanks for the review @njames93! This is my first contribution so I don't think I have permission to land this myself, is there someone that can do that for me?

njames93 added a comment.EditedAug 17 2022, 11:39 PM

Thanks for the review @njames93! This is my first contribution so I don't think I have permission to land this myself, is there someone that can do that for me?

Sure, which email would you like me to use for the commit?

Thanks for the review @njames93! This is my first contribution so I don't think I have permission to land this myself, is there someone that can do that for me?

Sure, which email would you like me to use for the commit?

Please use jwatts43@bloomberg.net!

This revision was automatically updated to reflect the committed changes.