readability-redundant-nested-if¶
Finds nested if statements that can be merged by combining their
conditions with &&.
Example:
if (a) {
if (b) {
work();
}
}
becomes
if ((a) && (b)) {
work();
}
The check also supports outer declaration conditions in C++17 and later:
if (bool X = ready()) {
if (can_run()) {
work();
}
}
becomes
if (bool X = ready(); X && (can_run())) {
work();
}
For if constexpr, dependent nested conditions are merged only when they can
be formed outside the discarded branch. This includes conditions such as
non-type template parameters and requires expressions, but excludes
conditions such as sizeof(typename T::type) after an earlier dependent
condition.
Options¶
- AllowUserDefinedBoolConversion¶
When set to true, the check also diagnoses chains whose merged conditions require user-defined conversion to
bool. Fix-its insertstatic_cast<bool>(...)where needed so the merged condition still uses built-in&&semantics. Default is false.