[clang-tools-extra] [clang-tidy] Add readability-use-rethrow check (PR #190580)

Daniil Dudkin via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 8 13:16:39 PDT 2026


================
@@ -0,0 +1,38 @@
+.. title:: clang-tidy - readability-use-rethrow
+
+readability-use-rethrow
+=======================
+
+Detects cases where a caught exception is explicitly re-thrown as a new copy,
+and suggests using a bare ``throw;`` instead.
+
+Throwing a caught exception by its variable name (e.g., ``throw e;``) instead
+of using a bare ``throw;`` creates a new copy of the exception. This can lead
+to object slicing if the exception was derived from the caught type, and it
+alters the original stack trace of the exception.
----------------
unterumarmung wrote:

I'm wondering if my initial judgement was wrong and it should be a `bugprone` check or something else.

https://github.com/llvm/llvm-project/pull/190580


More information about the cfe-commits mailing list