MyDeveloperDay updated this revision to Diff 191311.
MyDeveloperDay added a comment.

Minor modification to improve the `[=]` case

`[&Columns]` and `[Columns]` are not yet fixed and will not be correctly 
renamed to `[&columns]` and `[columns]`

But at least they are left unaltered


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

https://reviews.llvm.org/D59540

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===================================================================
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -501,3 +501,43 @@
 // CHECK-FIXES: {{^}}    int * const lc_PointerB = nullptr;{{$}}
 }
 
+
+bool Foo() {
+  bool Columns=false;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local variable 'Columns'
+// CHECK-FIXES: {{^}}  bool columns=false;
+  auto ptr=[&]{return Columns;}();
+// CHECK-FIXES: {{^}}  auto ptr=[&]{return columns;}();
+  return Columns;
+// CHECK-FIXES: {{^}}  return columns;
+}
+
+bool Foo1() {
+  bool Columns=false;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local variable 'Columns'
+// CHECK-FIXES: {{^}}  bool columns=false;
+  auto ptr=[=]{return Columns;}();
+// CHECK-FIXES: {{^}}  auto ptr=[=]{return columns;}();
+  return Columns;
+// CHECK-FIXES: {{^}}  return columns;
+}
+
+bool Foo2() {
+  bool Columns=false;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local variable 'Columns'
+// CHECK-FIXES: {{^}}  bool columns=false;
+  auto ptr=[&Columns]{return Columns;}();
+// XXX_CHECK-FIXES: {{^}}  auto ptr=[&columns]{return columns;}();
+  return Columns;
+// CHECK-FIXES: {{^}}  return columns;
+}
+
+bool Foo3() {
+  bool Columns=false;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local variable 'Columns'
+// CHECK-FIXES: {{^}}  bool columns=false;
+  auto ptr=[Columns]{return Columns;}();
+// XXX_CHECK-FIXES: {{^}}  auto ptr=[columns]{return columns;}();
+  return Columns;
+// CHECK-FIXES: {{^}}  return columns;
+}
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===================================================================
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -396,7 +396,7 @@
 
   if (isa<ObjCIvarDecl>(D) && NamingStyles[SK_ObjcIvar])
     return SK_ObjcIvar;
-  
+
   if (isa<TypedefDecl>(D) && NamingStyles[SK_Typedef])
     return SK_Typedef;
 
@@ -506,7 +506,7 @@
       return SK_ParameterPack;
 
     if (!Type.isNull() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_PointerParameter])
-        return SK_PointerParameter;
+      return SK_PointerParameter;
 
     if (NamingStyles[SK_Parameter])
       return SK_Parameter;
@@ -557,7 +557,7 @@
 
     if (Decl->isStaticLocal() && NamingStyles[SK_StaticVariable])
       return SK_StaticVariable;
- 
+
     if (Decl->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_LocalPointer])
       return SK_LocalPointer;
 
@@ -787,10 +787,28 @@
   }
 
   if (const auto *DeclRef = Result.Nodes.getNodeAs<DeclRefExpr>("declRef")) {
-    SourceRange Range = DeclRef->getNameInfo().getSourceRange();
-    addUsage(NamingCheckFailures, DeclRef->getDecl(), Range,
-             Result.SourceManager);
-    return;
+    const auto &Parents = Result.Context->getParents(*DeclRef);
+    bool LambdaDeclRef = false;
+
+    if (!Parents.empty()) {
+      const Stmt *ST = Parents[0].get<Stmt>();
+      // Step over the ImplicitCastExpr
+      if (ST && isa<ImplicitCastExpr>(ST)) {
+        const auto &CastParents = Result.Context->getParents(*ST);
+        if (!CastParents.empty())
+          ST = CastParents[0].get<Stmt>();
+      }
+
+      if (ST && isa<LambdaExpr>(ST))
+        LambdaDeclRef = true;
+    }
+
+    if (!LambdaDeclRef) {
+      SourceRange Range = DeclRef->getNameInfo().getSourceRange();
+      addUsage(NamingCheckFailures, DeclRef->getDecl(), Range,
+               Result.SourceManager);
+      return;
+    }
   }
 
   if (const auto *Decl = Result.Nodes.getNodeAs<NamedDecl>("decl")) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to