llvm/llvm-project

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

Open

#189 672 ouverte le 31 mars 2026

Voir sur GitHub
 (8 commentaires) (1 réaction) (1 assigné)C++ (10 782 forks)batch import
check-requestclang-tidygood first issue

Métriques du dépôt

Stars
 (26 378 stars)
Métriques de merge PR
 (Merge moyen 1j 2h) (1 000 PRs mergées en 30 j)

Description

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.

Guide contributeur