[PATCH] D40058: add check to avoid throwing objc exception according to Google Objective-C guide

Ben Hamilton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 15 14:33:30 PST 2017


benhamilton accepted this revision.
benhamilton added a comment.
This revision is now accepted and ready to land.

Looking good. Please rename the files correctly, or it will not build on Linux.



================
Comment at: clang-tidy/google/AvoidThrowingObjcExceptionCheck.cpp:23
+  Finder->addMatcher(objcThrowStmt().bind("throwStmt"), this);
+  Finder->addMatcher(objcMessageExpr(hasSelector("raise:format:"),
+                                     hasReceiverType(asString("NSException")))
----------------
Also need to match `raise:format:arguments:`.



================
Comment at: clang-tidy/google/AvoidThrowingObjcExceptionCheck.h:1
+//===--- AvoidThrowingObjCExceptionCheck.h - clang-tidy----------*- C++ -*-===//
+//
----------------
Don't forget to rename the file to AvoidThrowingObjcExceptionCheck.h.



================
Comment at: clang-tidy/google/CMakeLists.txt:5
   AvoidCStyleCastsCheck.cpp
+  AvoidThrowingObjcExceptionCheck.cpp
   DefaultArgumentsCheck.cpp
----------------
Rename to AvoidThrowingObjCExceptionCheck.cpp


================
Comment at: clang-tidy/google/GoogleTidyModule.cpp:18
 #include "AvoidCStyleCastsCheck.h"
+#include "AvoidThrowingObjCExceptionCheck.h"
 #include "DefaultArgumentsCheck.h"
----------------
I think you renamed the #include but not the file.. should test on Linux, it won't work with a case-sensitive file system ;)


================
Comment at: docs/ReleaseNotes.rst:63
+
+  Add new check to detect usage of @throw in Objective-C code, which should be avoided.
+
----------------
detect usage of @throw -> detect throwing exceptions


================
Comment at: docs/clang-tidy/checks/google-objc-avoid-throwing-exception.rst:6
+
+This check finds @throw usages in Objective-C files. For the same reason as the
+Google C++ style guide, we prefer not throwing exceptions from Objective-C code.
----------------
Can you include the link to the C++ style guide section here instead of at the end? http://google.github.io/styleguide/cppguide.html#Exceptions


================
Comment at: docs/clang-tidy/checks/google-objc-avoid-throwing-exception.rst:6
+
+This check finds @throw usages in Objective-C files. For the same reason as the
+Google C++ style guide, we prefer not throwing exceptions from Objective-C code.
----------------
benhamilton wrote:
> Can you include the link to the C++ style guide section here instead of at the end? http://google.github.io/styleguide/cppguide.html#Exceptions
finds @throw usages -> finds uses of throwing exceptions


https://reviews.llvm.org/D40058





More information about the cfe-commits mailing list