From: Stephane Moore Date: Thu, 21 Feb 2019 00:34:01 +0000 (+0000) Subject: [clang-tidy] Make google-objc-function-naming ignore implicit functions 🙈 X-Git-Tag: llvmorg-10-init~11530 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3eea706e3e54a1867fe3848ddfd64b47bbd5e721;p=platform%2Fupstream%2Fllvm.git [clang-tidy] Make google-objc-function-naming ignore implicit functions 🙈 Summary: 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 Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: jdoerfert, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58095 llvm-svn: 354534 --- diff --git a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp index 3eeb6fa..8096d65 100644 --- a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp @@ -93,12 +93,16 @@ void FunctionNamingCheck::registerMatchers(MatchFinder *Finder) { 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)))))) diff --git a/clang-tools-extra/test/clang-tidy/Inputs/Headers/stdio.h b/clang-tools-extra/test/clang-tidy/Inputs/Headers/stdio.h new file mode 100644 index 0000000..eebe9fd --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/Inputs/Headers/stdio.h @@ -0,0 +1,18 @@ +//===--- stdio.h - Stub header for tests ------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _STDIO_H_ +#define _STDIO_H_ + +// A header intended to contain C standard input and output library +// declarations. + +int printf(const char *, ...); + +#endif // _STDIO_H_ + diff --git a/clang-tools-extra/test/clang-tidy/google-objc-function-naming.m b/clang-tools-extra/test/clang-tidy/google-objc-function-naming.m index d0336d2..01433d9 100644 --- a/clang-tools-extra/test/clang-tidy/google-objc-function-naming.m +++ b/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 + +static void TestImplicitFunctionDeclaration(int a) { + // Call a builtin function so that the compiler generates an implicit + // function declaration. + printf("%d", a); +} typedef _Bool bool;