[PATCH] D43120: [clang-tidy] New checker for exceptions that are created but not thrown

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 9 07:35:25 PST 2018


aaron.ballman added a comment.

One concern I have is with RAII objects with "exception" in the name. You may already properly handle this, but I'd like to see a test case like:

  struct ExceptionRAII {
    ExceptionRAII() {}
    ~ExceptionRAII() {}
  };
  
  void foo() {
    ExceptionRAII E; // Don't trigger on this
  }



================
Comment at: clang-tidy/misc/ThrowKeywordMissingCheck.cpp:45
+  diag(TemporaryExpr->getLocStart(),
+       "exception instantiated but not bound (did you intend to 'throw'?)");
+}
----------------
I'm not keen on the wording here ("bound" isn't a common phrase for exceptions). How about `"suspicious exception object created but not thrown; did you mean 'throw %0'"` and then pass in the text for the object construction?


================
Comment at: docs/clang-tidy/checks/misc-throw-keyword-missing.rst:6
+
+This check warns about the potentially missing `throw` keyword. If a temporary object is created,
+but the object's type derives from (or the same as) a class that has 'EXCEPTION', 'Exception' or
----------------
about the potentially -> about a potentially


================
Comment at: docs/clang-tidy/checks/misc-throw-keyword-missing.rst:7
+This check warns about the potentially missing `throw` keyword. If a temporary object is created,
+but the object's type derives from (or the same as) a class that has 'EXCEPTION', 'Exception' or
+'exception' in its name, we can assume that the programmer's intention was to throw that object.
----------------
or the same as -> or is the same as


================
Comment at: docs/clang-tidy/checks/misc-throw-keyword-missing.rst:14
+  void f(int i) {
+    if(i < 0) {
+      // Exception is created but is not thrown
----------------
Can you format the code snippet?


https://reviews.llvm.org/D43120





More information about the cfe-commits mailing list