llvm/llvm-project

[clang-tidy] Add `readability-use-rethrow` check

開放

#189,672 建立於 2026年3月31日

 (8 則留言) (1 個反應) (1 位負責人)C++ (10,782 個分叉)batch import
check-requestclang-tidygood first issue

倉庫指標

星標
 (26,378 顆星)
PR 合併指標
 (平均合併 1天 2小時) (30 天內合併 1,000 個 PR)

描述

It would be useful to have a clang-tidy check that detects cases where code is clearly trying to rethrow the currently handled exception, but spells it as throw e; instead of throw;.

For example, code like this is easy to write:

try {
  f();
} catch (const std::exception &e) {
  log(e.what());
  throw e;
}

but if the intent is to rethrow the active exception, the clearer spelling is:

try {
  f();
} catch (const std::exception &e) {
  log(e.what());
  throw;
}

The latter expresses the intent directly and avoids the impression that the code is deliberately throwing the caught object as a new exception expression.

貢獻者指南