[clang-tools-extra] r356220 - Fixed global constant/variable naming check on C++ class for ObjC++ files.

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


Author: wizard
Date: Thu Mar 14 17:17:41 2019
New Revision: 356220

URL: http://llvm.org/viewvc/llvm-project?rev=356220&view=rev
Log:
Fixed global constant/variable naming check on C++ class for ObjC++ files.

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59283

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

Modified: clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp?rev=356220&r1=356219&r2=356220&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp Thu Mar 14 17:17:41 2019
@@ -79,12 +79,16 @@ void GlobalVariableDeclarationCheck::reg
 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")

Added: clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm?rev=356220&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm (added)
+++ clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm Thu Mar 14 17:17:41 2019
@@ -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;
+};




More information about the cfe-commits mailing list