It fixes the false positive when using constexpr if and where else cannot be removed:
Example:
if constexpr (sizeof(int) > 4) // ... return /* ... */; else // This else cannot be removed. // ... return /* ... */;
Differential D53372
[clang-tidy] Resolve readability-else-after-return false positive for constexpr if. curdeius on Oct 17 2018, 6:28 AM. Authored by
Details
It fixes the false positive when using constexpr if and where else cannot be removed: Example: if constexpr (sizeof(int) > 4) // ... return /* ... */; else // This else cannot be removed. // ... return /* ... */;
Diff Detail
Event TimelineComment Actions I think it would be good to add some more explanation as to *why* that else has to be kept. Comment Actions Do you mean add a comment in the code or just an explanation for the review? For the latter, e.g.: // unrelated types: struct type_a {}; struct type_b {}; auto f() { if constexpr(condition) { return type_a{}; } else { return type_b{}; } } In this case removing else will just provoke a compilation error. There may be some cases where you may remove else though. Comment Actions I was indeed talking about the review, thank you. I'm not sure, maybe this shouldn't be an option. Comment Actions Hmm, the latest patch only seems to have the changes to the test but not the implementation? |
Please add some of the warning text -- any warning will match this.