This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Enable more clang-tidy checks and list potential candidates
ClosedPublic

Authored by philnik on Mar 3 2022, 11:10 AM.

Details

Summary

These are some checks that make sense in libc++ IMO. The checks after #TODO: investigate these checks are candidates, but they can't be enabled without some cleanup.

Diff Detail

Event Timeline

philnik created this revision.Mar 3 2022, 11:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 11:10 AM
philnik requested review of this revision.Mar 3 2022, 11:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 11:10 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
philnik edited the summary of this revision. (Show Details)Mar 3 2022, 11:10 AM
ldionne accepted this revision as: ldionne.Mar 3 2022, 12:23 PM

I am favourable to this patch, however I think we all need to be on the same page that clang-tidy is not the absolute truth -- if we write some code that we deem valid or good for some reason, and if clang-tidy thinks the code is smelly, I don't want us to start blindly trying to satisfy clang-tidy. IOW, this is a tool to help us write better code -- it can't make decisions for us.

I am favourable to this patch, however I think we all need to be on the same page that clang-tidy is not the absolute truth -- if we write some code that we deem valid or good for some reason, and if clang-tidy thinks the code is smelly, I don't want us to start blindly trying to satisfy clang-tidy. IOW, this is a tool to help us write better code -- it can't make decisions for us.

I'd like to add the invariant that there has to be a comment explaining why clang-tidy is wrong somewhere. If clang-tidy complains it probably looks like a smell to a human reader, or it is a clang-tidy bug in which case we should add a link to the bug report. I'd also like to avoid a plain // NOLINT (and variants). Using // NOLINT(check) (and variants) makes it clear what clang-tidy warns about.

Quuxplusone added inline comments.Mar 3 2022, 1:56 PM
libcxx/.clang-tidy
27–30

I'd prefer not to encode arbitrary "magic numbers" in this file. IIUC, you picked these numbers basically by looking at all the code we've written in libc++ so far, taking the maximum (McCabe complexity|LoC length|whatever), and writing it down right here. But that's basically implying a rule: "We should never write any code that's more (complex|long|whatever) than we have ever written in the past." With all the new stuff in C++20, I don't think such a rule is justified.

50

I am favourable to this patch, however I think we all need to be on the same page that clang-tidy is not the absolute truth -- if we write some code that we deem valid or good for some reason, and if clang-tidy thinks the code is smelly, I don't want us to start blindly trying to satisfy clang-tidy. IOW, this is a tool to help us write better code -- it can't make decisions for us.

I'd like to add the invariant that there has to be a comment explaining why clang-tidy is wrong somewhere. If clang-tidy complains it probably looks like a smell to a human reader, or it is a clang-tidy bug in which case we should add a link to the bug report. I'd also like to avoid a plain // NOLINT (and variants). Using // NOLINT(check) (and variants) makes it clear what clang-tidy warns about.

As with //clang-format off, I'd strongly prefer to avoid //NOLINT comments. They add distraction for the human maintainer, and serve no beneficial purpose. 150% what Louis said: We should use computer tools to enforce consistency of libc++'s own style and rules; we should not add new rules motivated simply by the fact that there happens to be a convenient computer tool for checking them.
https://quoteinvestigator.com/2013/04/11/better-light/

philnik marked an inline comment as done.Mar 3 2022, 2:24 PM
philnik added inline comments.
libcxx/.clang-tidy
27–30

I think it's exactly the opposite: we should make the code more readable. I'm not saying that we should get these numbers as low as possible at any cost, but I do think that these functions should be refactored. It's not that hard to do and can significantly increase readability.
What things in C++20 do you think warrant such complex code?
(The worst offenders are money_get::__do_get, __bracket_expression::__exec and __intosort)

50

I'm not saying we should sprinkle the code with // NOLINT comments. I'm saying that if clang-tidy complains we should probably add a comment, because the code is in some way unusual. The other option is that it's a clang-tidy bug, in which case we should report it and remove the // NOLINT comment as soon as the bug has been fixed.

philnik updated this revision to Diff 413230.Mar 5 2022, 10:13 AM
philnik marked an inline comment as done.

Rebased

ldionne accepted this revision.Mar 8 2022, 5:08 AM

Please make sure CI passes.

This revision is now accepted and ready to land.Mar 8 2022, 5:08 AM
This revision was landed with ongoing or failed builds.Mar 8 2022, 5:15 AM
This revision was automatically updated to reflect the committed changes.