summaryrefslogtreecommitdiff
path: root/clang-tools-extra
diff options
context:
space:
mode:
authorStephane Moore <mog@google.com>2018-12-04 23:40:42 +0000
committerStephane Moore <mog@google.com>2018-12-04 23:40:42 +0000
commita6f039e2e8258ba1d4421d0995d20554e70ebbdf (patch)
tree3f7524ac6c9dd6bab4347f4a67d90ab498b8ee5e /clang-tools-extra
parent3e5d47c4c338a50597f13de434baddad5137d39d (diff)
[clang-tidy] Ignore namespaced and C++ member functions in google-objc-function-naming check 🙈
Summary: 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. Reviewers: benhamilton, aaron.ballman Reviewed By: aaron.ballman Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D55101
Diffstat (limited to 'clang-tools-extra')
-rw-r--r--clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp5
-rw-r--r--clang-tools-extra/test/clang-tidy/google-objc-function-naming.mm30
2 files changed, 33 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
index 7aeadd38c02..6d07472ef54 100644
--- a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
@@ -98,8 +98,9 @@ void FunctionNamingCheck::registerMatchers(MatchFinder *Finder) {
// 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"),
diff --git a/clang-tools-extra/test/clang-tidy/google-objc-function-naming.mm b/clang-tools-extra/test/clang-tidy/google-objc-function-naming.mm
new file mode 100644
index 00000000000..2e894575528
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/google-objc-function-naming.mm
@@ -0,0 +1,30 @@
+// 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; }
+};