Description
If a condition variable is declared in the second clause of a three-clause for
loop, clang doesn't destroy it when constant-evaluating the loop. For example:
struct X {
constexpr ~X() noexcept(false) { throw "oops"; }
constexpr operator bool() {
return b;
}
bool b;
};
constexpr bool f() {
for (bool b = false; X x = {b}; b = true) {}
return true;
}
static_assert(f());
Clang treats this as constant, but the destructor for x
throws an exception.
It looks like the problem is that we fail to call IterScope.destroy()
here, when terminating a loop iteration because the condition evaluated to false
.