This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] bugprone-forwarding-reference-overload: support non-type template parameters
ClosedPublic

Authored by jwtowner on May 30 2021, 7:40 PM.

Details

Summary

Many concepts emulation libraries, such as the one found in Range v3, tend to
use non-type template parameters for the enable_if type expression, due to
their versatility in template functions and constructors containing variadic
template parameter packs.

Unfortunately the bugprone-forwarding-reference-overload check does not
handle non-type template parameters, as was first noted in this bug report:
https://bugs.llvm.org/show_bug.cgi?id=38081

This patch fixes this long standing issue and allows for the check to be suppressed
with the use of a non-type template parameter containing enable_if or enable_if_t in
the type expression, so long as it has a default literal value.

Diff Detail

Event Timeline

jwtowner created this revision.May 30 2021, 7:40 PM
jwtowner requested review of this revision.May 30 2021, 7:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2021, 7:40 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
jwtowner added inline comments.May 30 2021, 7:53 PM
clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
83

Note that I'm using hasDescendant here, because sometimes the literal ends up inside of an ImplicitCastExpr node and sometimes its a direct child of the NonTypeTemplateParmDecl node. I'm not sure exactly what causes the difference.

Friendly bump in case this was missed. Without this fix, bugprone-forwarding-reference-overload is not currently usable in a lot of codebases.

aaron.ballman accepted this revision.Jul 22 2021, 6:50 AM

Thank you for the ping, this fell off my radar. LGTM aside from some small nits.

clang-tools-extra/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst
34
57

Can you add the newline back?

This revision is now accepted and ready to land.Jul 22 2021, 6:50 AM
jwtowner updated this revision to Diff 361289.Jul 23 2021, 11:57 AM

Improved the code formatting of the samples in the documentation and added back in the newline at the end of the bugprone-forwarding-reference-overload.rst

jwtowner marked 2 inline comments as done.Jul 23 2021, 11:59 AM

It should be good to go. I do not have commit access so feel free to commit. Thanks!

clang-tools-extra/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst
34

The reason I didn't put the spaces in here was that I was trying to match the style above for enable_if_t<is_special<T>,void>. I can add a space after the comma there as well.

57

Will do! Sorry about this.

It should be good to go. I do not have commit access so feel free to commit. Thanks!

Thanks! What name and email address would you like me to use for patch attribution?

clang-tools-extra/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst
34

Ah, good call. The way it is now is good for me. Thank you!

jwtowner marked 2 inline comments as done.Jul 28 2021, 9:57 PM

Thanks! What name and email address would you like me to use for patch attribution?

The following will do:

Jesse Towner <townerj AT gmail.com>

aaron.ballman closed this revision.Jul 29 2021, 4:02 AM

I've committed on your behalf in 68546c9d6fc54a7ca7ad487cd4b6a5dafea9b4f3, thank you for the fix!