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

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 7 08:49:42 PST 2020


njames93 marked an inline comment as done.
njames93 added a comment.

Would you say this behaviour is better?

  void baz() {
    auto MyFunctionPtr = getPtrFunction();
    // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: 'auto MyFunctionPtr' can be declared as 'auto *MyFunctionPtr'
    // CHECK-FIXES-NOT: {{^}}  auto *MyFunctionPtr = getPtrFunction();
    auto MyFunctionVal = getValFunction();
    // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: 'auto MyFunctionVal' can be declared as 'auto *MyFunctionVal'
    // CHECK-FIXES-NOT: {{^}}  auto *MyFunctionVal = getValFunction();
  
    auto LambdaTest = [] { return 0; };
    // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: 'auto LambdaTest' can be declared as 'auto *LambdaTest'
    // CHECK-FIXES-NOT: {{^}}  auto *LambdaTest = [] { return 0; };#
  
    auto LambdaTest2 = +[] { return 0; };
    // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: 'auto LambdaTest2' can be declared as 'auto *LambdaTest2'
    // CHECK-FIXES-NOT: {{^}}  auto *LambdaTest2 = +[] { return 0; };
  }



================
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'
----------------
JonasToth wrote:
> 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.
It gets handled the same as retty (*)(params), I should probably make function pointers in general not be converted


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

https://reviews.llvm.org/D72217





More information about the cfe-commits mailing list