[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 7 08:30:45 PST 2020


JonasToth added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp:61
+      Diag << FixItHint::CreateReplacement(
+          FixItRange, IsPtrConst ? "const auto *const " : "auto *const ");
+    } else {
----------------
njames93 wrote:
> JonasToth wrote:
> > the outer const might be debatable. some code-bases don't want the `* const`, i think neither does LLVM. maybe that could be configurable?
> The outer const is only there if the vardecl was already declared as const
> 
> ```
> const auto X = getPointer();
> auto *const X = getPointer();
> ```
> Those 2 decls are functionally identical, both mean that the pointer X can't change but X is pointing to data that can change
I see. That is ok then, but might be surprising to some users, as they might think the pointee itself is const (which it isn't). I think thats something worth to write in the documentation.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp:183
+
+  auto LambdaTest = [] { return 0; };
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: 'auto LambdaTest' can be declared as 'auto *LambdaTest'
----------------
How does that beatiful code-construct get handled?

```
auto * function_ptr = +[](int) {};
```
The lambda is actually converted to a function pointer through the `+`-operator. Not sure this happens anywhere, but it can happen.
So the case:
```
auto unnotice_ptr = +[](int) {};
```
should be transformed.


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

https://reviews.llvm.org/D72217





More information about the cfe-commits mailing list