[PATCH] D97196: [clang-tidy] Add new check 'bugprone-unhandled-exception-at-new'.
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 12 08:31:49 PDT 2021
aaron.ballman added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp:28-30
+ // Generic catch handler should match anything.
+ if (CatchS->getCaughtType().isNull())
+ return true;
----------------
I think this should move above the call to `InnertMatcher.matches()` so that the inner matcher doesn't have to worry quite as much about getting null types.
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst:7
+Finds calls to ``new`` that may throw ``std::bad_alloc`` exception and
+the exception handler is missing.
+
----------------
This isn't quite accurate -- if the exception handler is missing or doesn't handle either `std::bad_alloc` or `std::exception`.
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst:17
+
+Calls to ``new`` can throw exception of type ``bad_alloc`` that should be
+handled by the code. Alternatively the nonthrowing form of ``new`` can be
----------------
================
Comment at: clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp:20
+using badalloc3 = std::bad_alloc &;
+
+void *operator new(std::size_t, int, int);
----------------
Another interesting test case would be when the user subclasses `std::bad_alloc` and throws errors of the subclass type from the allocation function which are in/correctly caught.
================
Comment at: clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp:20
+
+void f1() noexcept {
+ int *I1 = new int;
----------------
aaron.ballman wrote:
> It would be useful to also have a test with a function-try-block to ensure those are handled properly.
Still missing this test -- you should add one like:
```
void func() try {
int *i = new int;
} catch (const std::bad_alloc &) {
}
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97196/new/
https://reviews.llvm.org/D97196
More information about the cfe-commits
mailing list