[PATCH] D75569: [clang-tidy] New check for methods marked __attribute__((unavailable)) that do not override a method from a superclass.

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 5 01:09:02 PST 2020


njames93 added a comment.

Fix the test case.



================
Comment at: clang-tools-extra/clang-tidy/objc/MethodUnavailableNotOverrideCheck.cpp:29
+// intended to be matched here.
+AST_MATCHER(ObjCMethodDecl, isUnavailableMethodNotOverriding) {
+  return !Node.isOverriding() && Node.hasAttr<UnavailableAttr>();
----------------
Should probably be in an anonymous namespace this as you don't intend it to be visible in another translation unit.


================
Comment at: clang-tools-extra/clang-tidy/objc/MethodUnavailableNotOverrideCheck.cpp:34
+void MethodUnavailableNotOverrideCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().ObjC)
+    return;
----------------
See https://reviews.llvm.org/D75340


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/objc-method-unavailable-not-override.m:34
+// Verify check when using a macro that expands to the unavailable attribute.
+- (void)methodC NS_UNAVAILABLE;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: method 'methodC' is marked unavailable but does not override a superclass method [objc-method-unavailable-not-override]
----------------
Generally we are cautious about modifying MACRO usages in clang_tidy as we don't know if its definition can change based on configuration, perhaps its safer to just warn instead of providing a fix it


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/objc-method-unavailable-not-override.m:51
+// Verify that fixes exist to delete entire method declarations:
+// CHECK-FIXES: {{^\s*$}}
----------------
This is not a satisfactory check, it will ensure at least one method has been deleted but it wont ensure all methods have been deleted. Would probably be safer putting a unique comment on the line and having a check fix that checks for an empty line and the comment for each case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75569





More information about the cfe-commits mailing list