| Issue |
169961
|
| Summary |
Add option to readability-function-size to not count lambdas as nesting level
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
dkaszews
|
I like to be pretty strict with nesting, only allowing for 3 levels - function, loop, condition. I am however running into issues when I need to pass a loop+condition into some other function as a lambda:
```cpp
// NOLINTNEXTLINE(readability-function-size): Nesting counts lambda as level
void explorer_impl::filter_entries(storage& stack) {
// Nesting level 1
auto& entries = stack.back().entries;
const auto predicate = [&stack](const auto& entry) {
// Nesting level 2
for (auto it = stack.crbegin(); it != stack.crend(); ++it) {
// Nesting level 3
const auto decision = filter_entry(it->filter, entry);
if (decision != glob::decision::undecided) {
// Nesting level 4
return decision == glob::decision::ignored;
}
}
return false;
};
entries.erase(
std::remove_if(entries.begin(), entries.end(), predicate),
entries.end()
);
}
```
While there are indeed 4 different nested scopes, I would like an option to treat the lambda as a separate function, since that is what it is in my mental model as it has its own `return` scope. In some cases I would just make it an actual function to reduce indentation, but here I need the capture functionality. If I rewrote it as a pre-lambda functor, then `predicate` would be its own 3-level function and the check would pass.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs