[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.

Yan Zhang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 14 17:16:40 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL356220: Fixed global constant/variable naming check on C++ class for ObjC++ files. (authored by Wizard, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59283

Files:
  clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm


Index: clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
+++ clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
+
+ at class NSString;
+static NSString* const myConstString = @"hello";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const kMyConstString = @"hello";
+
+class MyTest {
+    static int not_objc_style;
+};
Index: clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -79,12 +79,16 @@
 void GlobalVariableDeclarationCheck::check(
     const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs<VarDecl>("global_var")) {
+    if (Decl->isStaticDataMember())
+      return;
     diag(Decl->getLocation(),
          "non-const global variable '%0' must have a name which starts with "
          "'g[A-Z]'")
         << Decl->getName() << generateFixItHint(Decl, false);
   }
   if (const auto *Decl = Result.Nodes.getNodeAs<VarDecl>("global_const")) {
+    if (Decl->isStaticDataMember())
+      return;
     diag(Decl->getLocation(),
          "const global variable '%0' must have a name which starts with "
          "an appropriate prefix")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59283.190758.patch
Type: text/x-patch
Size: 1819 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190315/9d15f588/attachment.bin>


More information about the cfe-commits mailing list