This is an archive of the discontinued LLVM Phabricator instance.

Added check uniqueptr-delete-release to replace "delete x.release()" with "x = nullptr"
ClosedPublic

Authored by sbenza on Sep 25 2015, 2:42 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

sbenza updated this revision to Diff 35764.Sep 25 2015, 2:42 PM
sbenza retitled this revision from to Added check uniqueptr-delete-release to replace "delete x.release()" with "x = nullptr".
sbenza updated this object.
sbenza added a reviewer: alexfh.
alexfh edited edge metadata.Sep 26 2015, 4:44 PM

Nice check! One comment (quite usual ;).

test/clang-tidy/readability-uniqueptr-delete-release.cpp
25 ↗(On Diff #35764)

I'd anchor the pattern to the start of line to verify correct replacement of "delete ".

36 ↗(On Diff #35764)

Please add tests for code in templates with multiple instantiations and for code in macros. I suspect these cases need special treatment, which is not currently done.

sbenza updated this revision to Diff 35901.Sep 28 2015, 12:58 PM
sbenza marked an inline comment as done.
sbenza edited edge metadata.

added more test cases and fixed the check for them.

sbenza marked an inline comment as done.Sep 28 2015, 12:58 PM
aaron.ballman added inline comments.Oct 13 2015, 7:48 AM
clang-tidy/readability/UniqueptrDeleteReleaseCheck.h
19 ↗(On Diff #35901)

Is there a reason for = nullptr instead of .reset(); ?

sbenza added inline comments.Oct 14 2015, 7:49 AM
clang-tidy/readability/UniqueptrDeleteReleaseCheck.h
19 ↗(On Diff #35901)

Preference of the author and initial reviewer?
They are equivalent.

aaron.ballman accepted this revision.Oct 14 2015, 8:09 AM
aaron.ballman edited edge metadata.

LGTM!

clang-tidy/readability/UniqueptrDeleteReleaseCheck.h
19 ↗(On Diff #35901)

While equivalent, one may be considered more readable than another (in either direction!). For me, personally, I prefer seeing .reset() because it's a reminder to me that this object is also being destroyed. I don't have overly strong opinions though, and don't think it's worth some sort of user-configurability.

This revision is now accepted and ready to land.Oct 14 2015, 8:09 AM
This revision was automatically updated to reflect the committed changes.