This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Implement bugprone-incorrect-enable-if
ClosedPublic

Authored by ccotter on Aug 6 2023, 12:11 PM.

Details

Summary

Detects incorrect usages of std::enable_if that don't name the
nested 'type' type.

Diff Detail

Event Timeline

ccotter created this revision.Aug 6 2023, 12:11 PM
ccotter requested review of this revision.Aug 6 2023, 12:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2023, 12:11 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ccotter updated this revision to Diff 547599.Aug 6 2023, 12:23 PM
  • Edited wrong file
PiotrZSL added inline comments.Aug 6 2023, 1:05 PM
clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
58
62–63

do we still need typename in C++20 in this context ?
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0634r3.html

68

since C++14 we should recommend using enable_if_t

clang-tools-extra/docs/ReleaseNotes.rst
129
clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst
22

shoudnlt be enable_if ?

35

this is valid usage, uses enable_if_t

38

this may not compile, anyway, what if "type" got "type" ?:P

45

should be suffucient

48

maybe "Consider"

ccotter added inline comments.Aug 6 2023, 1:31 PM
clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
68

I didn't add replacement logic for C++14 or C++20 since there are separate tools for those, and though it'd be cleaner to have independent set of tools (e.g., first run bugprone-incorrect-enable-if, then run modernize-type-traits).

Do you have plans to also detect the bugprone scenario described in the Notes here?

https://en.cppreference.com/w/cpp/types/enable_if

No need to have it in this patch, but would be good to keep it in mind if we want to add it in the future (preferably) or create a separate check.

Eugene.Zelenko added inline comments.
clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst
7

Please synchronize with statement in Release Notes after Piotr's comment addressed.

ccotter updated this revision to Diff 549777.Aug 13 2023, 8:07 PM
ccotter marked 9 inline comments as done.
  • Fix docs, handle C++20 simplification
ccotter marked an inline comment as done.Aug 13 2023, 8:07 PM
ccotter added inline comments.
clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
62–63

Oh, I did not know that. Thanks!

ccotter marked an inline comment as done.Aug 13 2023, 8:28 PM

> Do you have plans to also detect the bugprone scenario described in the Notes here?

I didn't have plans in this review, or in the immediate future after. I did name this check broadly as "bugprone-incorrect-enable-if," so I imagine this other scenario could go into this new check.

PiotrZSL accepted this revision.Aug 14 2023, 1:02 AM

LGTM (+-)

This revision is now accepted and ready to land.Aug 14 2023, 1:02 AM

I'm pushing this, if you want to change anything else, just please open new review.

This revision was automatically updated to reflect the committed changes.