This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add a checker that removes deducible arguments from std::make_pair
ClosedPublic

Authored by bkramer on Jul 14 2014, 9:03 AM.

Details

Summary

Those may be incompatible with C++11 and are unnecessary. We suggest
removing the template arguments when they match the types of the make_pair
arguments or replace it with std::pair and explicit template arguments when
not.

Diff Detail

Repository
rL LLVM

Event Timeline

bkramer updated this revision to Diff 11386.Jul 14 2014, 9:03 AM
bkramer retitled this revision from to [clang-tidy] Add a checker that removes deducible arguments from std::make_pair.
bkramer updated this object.
bkramer edited the test plan for this revision. (Show Details)
bkramer added reviewers: alexfh, djasper.
bkramer added a subscriber: Unknown Object (MLST).
alexfh accepted this revision.Jul 15 2014, 2:30 AM
alexfh edited edge metadata.

Looks good provided you address the comments.

clang-tidy/google/ExplicitMakePairCheck.cpp
41 ↗(On Diff #11386)

nit: I'd better not crash here even if someone defines their own ::std::make_pair.

43 ↗(On Diff #11386)

nit: Missing comma after "match"?

test/clang-tidy/google-explicit-make-pair.cpp
16 ↗(On Diff #11386)

Please add tests with make_pair in template instantiations and in a macro.

This revision is now accepted and ready to land.Jul 15 2014, 2:30 AM
bkramer closed this revision.Jul 15 2014, 2:59 AM
bkramer updated this revision to Diff 11426.

Closed by commit rL213058 (authored by d0k).

alexfh added inline comments.Jul 15 2014, 5:57 AM
clang-tools-extra/trunk/test/clang-tidy/google-explicit-make-pair.cpp
18

I assume the check should suggest replacements in cases where there are no dependent types, but could you add a test? And one more instantiation, so that we actually test a case where something can go wrong due to templates.

bkramer added inline comments.Jul 15 2014, 6:03 AM
clang-tools-extra/trunk/test/clang-tidy/google-explicit-make-pair.cpp
18

We completely ignore code in template instantiations at the moment. It would be nice to check for code in templates that does not contain any dependencies on the template arguments but it's not tricky to match (or do we have an ASTMatcher for it?)

alexfh added inline comments.Jul 15 2014, 6:11 AM
clang-tools-extra/trunk/test/clang-tidy/google-explicit-make-pair.cpp
18

Yes, we ignore code in template _instantiations_. However, template _definitions_ are handled as usual. See a test for this in test/clang-tidy/avoid-c-style-casts.cpp:78