This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Don't check decltype return types in `readability-const-return-type`
ClosedPublic

Authored by Izaron on Feb 10 2022, 12:12 PM.

Details

Summary

The checker removes consts that are superfluos and badly affect
readability. decltype(auto)/decltype(expr) are often const-qualified, but
have no effect on readability and usually can't stop being const-qualified
without significant code change.

Fixes https://github.com/llvm/llvm-project/issues/52890

Diff Detail

Event Timeline

Izaron created this revision.Feb 10 2022, 12:12 PM
Izaron requested review of this revision.Feb 10 2022, 12:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2022, 12:12 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I think we don't need to update the docs
(https://clang.llvm.org/extra/clang-tidy/checks/readability-const-return-type.html)
Because a user would expect this behaviour.

If this review is eventually approved, kindly please merge the commit on my behalf =) As I don't have merge access. My name is Evgeny Shulgin and email is izaronplatz@gmail.com. Sorry for inconvenience!

I think we don't need to update the docs
(https://clang.llvm.org/extra/clang-tidy/checks/readability-const-return-type.html)
Because a user would expect this behaviour.

If this review is eventually approved, kindly please merge the commit on my behalf =) As I don't have merge access. My name is Evgeny Shulgin and email is izaronplatz@gmail.com. Sorry for inconvenience!

You've submitted some quality patches already, would you be interested in obtaining commit privileges (https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access)?

clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
56–58

I think we might as well hit all the local qualifiers instead of just const, WDYT? e.g., volatile et al via hasLocalQualifiers()

111

We don't usually use top-level const qualification for locals.

112

How about a TypeOfType? (The GCC typeof(foo) extension)

MTC added a subscriber: MTC.Feb 22 2022, 6:00 PM
Izaron updated this revision to Diff 416035.Mar 16 2022, 5:35 PM

Don't warn on non-toplevel-const TypeOfType

Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2022, 5:35 PM
Izaron marked 3 inline comments as done.Mar 16 2022, 5:38 PM

You've submitted some quality patches already, would you be interested in obtaining commit privileges (https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access)?

Thanks! I obtained the commit access =) Now I don't have to ask other peoples commit on my behalf.

clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
56–58

In this case the checker will complain on this code:

const int i = 1;
volatile decltype(i) n() {
  return 12345;
}
warning: return type 'volatile decltype(i)' (aka 'const volatile int') is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]

That wouldn't be the correct outcome.

I added the test for the snippet above.

112

Thanks! Didn't know about this extension. Now the checker filters this out.

Izaron marked 2 inline comments as done.Mar 16 2022, 5:38 PM
aaron.ballman accepted this revision.Mar 17 2022, 4:25 AM

LGTM!

clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
56–58

Great, thank you!

This revision is now accepted and ready to land.Mar 17 2022, 4:25 AM