[PATCH] D55101: [clang-tidy] Ignore namespaced and C++ member functions in google-objc-function-naming check 🙈

Stephane Moore via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 29 17:56:16 PST 2018


stephanemoore created this revision.
stephanemoore added reviewers: benhamilton, aaron.ballman.
Herald added subscribers: cfe-commits, xazax.hun.

The google-objc-function-naming check applies to functions that are not namespaced and should not be applied to C++ member functions. Such function declarations should be ignored by the check to avoid false positives in Objective-C++ sources.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D55101

Files:
  clang-tidy/google/FunctionNamingCheck.cpp
  test/clang-tidy/google-objc-function-naming.mm


Index: test/clang-tidy/google-objc-function-naming.mm
===================================================================
--- /dev/null
+++ test/clang-tidy/google-objc-function-naming.mm
@@ -0,0 +1,28 @@
+// RUN: %check_clang_tidy %s google-objc-function-naming %t
+
+void printSomething() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function name 'printSomething' not using function naming conventions described by Google Objective-C style guide
+
+void PrintSomething() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function name 'PrintSomething' not using function naming conventions described by Google Objective-C style guide
+
+void ABCBad_Name() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function name 'ABCBad_Name' not using function naming conventions described by Google Objective-C style guide
+
+namespace {
+
+int foo() { return 0; }
+
+}
+
+namespace bar {
+
+int convert() { return 0; }
+
+}
+
+class Baz {
+  public:
+    int value() { return 0; }
+};
+
Index: clang-tidy/google/FunctionNamingCheck.cpp
===================================================================
--- clang-tidy/google/FunctionNamingCheck.cpp
+++ clang-tidy/google/FunctionNamingCheck.cpp
@@ -98,8 +98,9 @@
   // main.
   Finder->addMatcher(
       functionDecl(
-          unless(isExpansionInSystemHeader()),
-          unless(anyOf(isMain(), matchesName(validFunctionNameRegex(true)),
+          unless(anyOf(isExpansionInSystemHeader(), cxxMethodDecl(),
+                       hasAncestor(namespaceDecl()), isMain(),
+                       matchesName(validFunctionNameRegex(true)),
                        allOf(isStaticStorageClass(),
                              matchesName(validFunctionNameRegex(false))))))
           .bind("function"),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55101.176007.patch
Type: text/x-patch
Size: 1752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181130/38c19c21/attachment.bin>


More information about the cfe-commits mailing list