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

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 17 04:25:51 PDT 2022


aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!



================
Comment at: clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp:56-58
+AST_MATCHER(QualType, isLocalConstQualified) {
+  return Node.isLocalConstQualified();
+}
----------------
Izaron wrote:
> aaron.ballman wrote:
> > I think we might as well hit all the local qualifiers instead of just `const`, WDYT? e.g., `volatile` et al via `hasLocalQualifiers()`
> 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.
Great, thank you!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119470/new/

https://reviews.llvm.org/D119470



More information about the cfe-commits mailing list