Open LegalizeAdulthood opened 1 month ago
@llvm/issue-subscribers-bug
Author: Richard Thomson (LegalizeAdulthood)
@llvm/issue-subscribers-clang-tidy
Author: Richard Thomson (LegalizeAdulthood)
Reduced/compilable:
#include <cstdlib>
int main() {
int i{};
if (int x = rand(); x == 0) {
throw 0;
}
else {
i = x;
}
return i;
}
https://godbolt.org/z/oPbWxaEdK
To be fair, it is possible to rewrite this without else after return:
int main() {
int i{};
{
int x = rand();
if (x == 0) {
throw 0;
i = x;
}
return i;
}
Suppose you introduce a variable in the scope of the
if
statement like so:readability-else-after-return
doesn't recognize the use of the scoped variable in the else and flags the else after return as a violation. This is a false positive.