Index: clang-tidy/readability/IdentifierNamingCheck.cpp =================================================================== --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -396,7 +396,7 @@ if (isa(D) && NamingStyles[SK_ObjcIvar]) return SK_ObjcIvar; - + if (isa(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("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(); + // Step over the ImplicitCastExpr + if (ST && isa(ST)) { + const auto &CastParents = Result.Context->getParents(*ST); + if (!CastParents.empty()) + ST = CastParents[0].get(); + } + + if (ST && isa(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("decl")) { 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; +}