[PATCH] D58095: [clang-tidy] Make google-objc-function-naming ignore implicit functions 🙈

Stephane Moore via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 12 16:56:25 PST 2019


stephanemoore updated this revision to Diff 186566.
stephanemoore added a comment.

Create a new header stdio.h under //test/clang-tidy/Inputs/Headers/ to contain declaration of
`printf` and import the new header to `google-objc-function-naming.m`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58095

Files:
  clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
  clang-tools-extra/test/clang-tidy/Inputs/Headers/stdio.h
  clang-tools-extra/test/clang-tidy/google-objc-function-naming.m


Index: clang-tools-extra/test/clang-tidy/google-objc-function-naming.m
===================================================================
--- clang-tools-extra/test/clang-tidy/google-objc-function-naming.m
+++ clang-tools-extra/test/clang-tidy/google-objc-function-naming.m
@@ -1,4 +1,12 @@
-// RUN: %check_clang_tidy %s google-objc-function-naming %t
+// RUN: %check_clang_tidy %s google-objc-function-naming %t -- -- -isystem %S/Inputs/Headers
+
+#include <stdio.h>
+
+static void TestImplicitFunctionDeclaration(int a) {
+  // Call a builtin function so that the compiler generates an implicit
+  // function declaration.
+  printf("%d", a);
+}
 
 typedef _Bool bool;
 
Index: clang-tools-extra/test/clang-tidy/Inputs/Headers/stdio.h
===================================================================
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/Inputs/Headers/stdio.h
@@ -0,0 +1,7 @@
+#ifndef _STDIO_H_
+#define _STDIO_H_
+
+int printf(const char *, ...);
+
+#endif // _STDIO_H_
+
Index: clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
@@ -93,12 +93,16 @@
   if (!getLangOpts().ObjC)
     return;
 
-  // Match function declarations that are not in system headers and are not
-  // main.
+  // Enforce Objective-C function naming conventions on all functions except:
+  // • Functions defined in system headers.
+  // • C++ member functions.
+  // • Namespaced functions.
+  // • Implicitly defined functions.
+  // • The main function.
   Finder->addMatcher(
       functionDecl(
           unless(anyOf(isExpansionInSystemHeader(), cxxMethodDecl(),
-                       hasAncestor(namespaceDecl()), isMain(),
+                       hasAncestor(namespaceDecl()), isMain(), isImplicit(),
                        matchesName(validFunctionNameRegex(true)),
                        allOf(isStaticStorageClass(),
                              matchesName(validFunctionNameRegex(false))))))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58095.186566.patch
Type: text/x-patch
Size: 2122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190213/91eebb3a/attachment.bin>


More information about the cfe-commits mailing list