[PATCH] D97196: [clang-tidy] Add new check 'bugprone-unhandled-exception-at-new'.

Balázs Kéri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 30 03:47:59 PDT 2021


balazske added inline comments.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp:143
+  f_est_noexcept_dependent_used<true>();
+}
----------------
balazske wrote:
> aaron.ballman wrote:
> > You have tests for placement new with `nothrow_t`, but I think other forms of placement new are also very interesting to test as those typically don't throw.
> > 
> > Additionally, perhaps tests where the allocation functions have been replaced by the user (such as a class allocation function)?
> I realized that the case of user-defined constructor or allocation function allows to throw any kind of exception. So the check should be improved to handle this case: Not rely on the syntax of new expression, instead check if the called allocation function or the called constructor may throw, and if yes, check what exceptions are possible. What is your opinion, is it a better approach?
> (And a function to collect all possible exceptions called from a function is needed, `ExceptionAnalyzer` seems usable.)
It looks like that the user is free to define custom `operator new` and any constructor called that may throw any exception. Even in the "nothrow" case it is possible to use a constructor that may throw? If we would analyze every possible throwable exception that may come out from a new-expression, the checker would end up almost in a general checker that checks for uncaught exceptions. At least it is easy to extend.


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