This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add check for initialization of `absl::Cleanup`.
ClosedPublic

Authored by CJ-Johnson on Nov 4 2021, 9:02 AM.

Details

Summary

Suggests switching the initialization pattern of absl::Cleanup instances from the factory function to class template argument deduction (CTAD) in C++17 and higher.

Diff Detail

Event Timeline

CJ-Johnson created this revision.Nov 4 2021, 9:02 AM
CJ-Johnson requested review of this revision.Nov 4 2021, 9:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2021, 9:02 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
CJ-Johnson updated this revision to Diff 384773.Nov 4 2021, 9:06 AM

Remove unwanted changes

CJ-Johnson updated this revision to Diff 384774.Nov 4 2021, 9:06 AM

Add trailing newline

ymandel retitled this revision from Suggests switching the initialization pattern of absl::Cleanup instances from the factory function to class template argument deduction (CTAD) in C++17 and higher. to [clang-tidy] Add check for initialization of `absl::Cleanup`..Nov 4 2021, 10:12 AM
ymandel edited the summary of this revision. (Show Details)
ymandel accepted this revision.Nov 4 2021, 10:21 AM

Nice!

clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
20
47–50

nit: move this inline into the class declaration. Serves as documentation for the class then as well (in that a reader can look in the header and see the target language).

clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.h
21
clang-tools-extra/test/clang-tidy/checkers/abseil-cleanup-ctad.cpp
8–21

Since the tests depend on the mock of the Cleanup declaration, have you run this on real code examples to double-check that it works as expected? Sometimes the divergence means real code can have unexpected implicit nodes that subtly impact the results, so it's always good to verify the mocks themselves in some way.

42

nit: this subtle, i'd add a comment pointing out the parens.

43

Here and below: you can truncate to 80 chars, any repeated message. We typically only check the whole message for the first appearance.

This revision is now accepted and ready to land.Nov 4 2021, 10:21 AM
CJ-Johnson marked 4 inline comments as done.Nov 8 2021, 7:03 AM

Thanks for the review! I'll apply the same fixes to the string_view diff as well

CJ-Johnson updated this revision to Diff 385487.Nov 8 2021, 7:04 AM

Address nits and update the absl::Cleanup stub to be accurate with the real interface (with associated changes to the AST matcher)

CJ-Johnson marked 2 inline comments as done.Nov 8 2021, 7:06 AM
CJ-Johnson updated this revision to Diff 385489.Nov 8 2021, 7:06 AM

Fix documentation nit

ymandel accepted this revision.Nov 8 2021, 7:22 AM
This revision was automatically updated to reflect the committed changes.