stephanemoore created this revision. Herald added subscribers: cfe-commits, xazax.hun. Herald added a project: clang.
Implicit functions are outside the control of source authors and should be exempt from style restrictions. Tested via running clang tools tests. This is an amended followup to https://reviews.llvm.org/D57207 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D58095 Files: clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp 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,5 +1,20 @@ // RUN: %check_clang_tidy %s google-objc-function-naming %t +// Declare a builtin function so that we can invoke the function below to +// generate an implicit function declaration (we intentionally do not import +// <stdio.h> as we cannot guarantee its availability). +// +// google-objc-function-naming is suppressed for this declaration as it must +// match the builtin function declaration. Under normal conditions, this +// function would be declared in a system header. +int printf(const char *, ...); // NOLINT(google-objc-function-naming) + +static void TestImplicitFunctionDeclaration(int a) { + // Call a builtin function so that the compiler generates an implicit + // function declaration. + printf("%d", a); +} + typedef _Bool bool; static bool ispositive(int a) { return a > 0; } 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))))))
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,5 +1,20 @@ // RUN: %check_clang_tidy %s google-objc-function-naming %t +// Declare a builtin function so that we can invoke the function below to +// generate an implicit function declaration (we intentionally do not import +// <stdio.h> as we cannot guarantee its availability). +// +// google-objc-function-naming is suppressed for this declaration as it must +// match the builtin function declaration. Under normal conditions, this +// function would be declared in a system header. +int printf(const char *, ...); // NOLINT(google-objc-function-naming) + +static void TestImplicitFunctionDeclaration(int a) { + // Call a builtin function so that the compiler generates an implicit + // function declaration. + printf("%d", a); +} + typedef _Bool bool; static bool ispositive(int a) { return a > 0; } 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))))))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits