Consider: #include <cassert> #include <iostream> struct X { bool alive = true; ~X() { alive = false; } explicit operator bool() const { return true; } } ; int main() { for(int i = 0; X x = X(); assert(x.alive)) if (++i == 3) break; else std::cout << i << std::endl; } When compiled with gcc trunk, the program outputs: 1 a.out: t.cpp:14: int main(): Assertion `x.alive' failed. When compiled with clang trunk, the program outputs: 1 2
Confirmed. https://godbolt.org/z/MfbrcG https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86769 is a duplicate.
PR86769 has a nicer test, so closing this one. Thanks for finding the dup. *** This bug has been marked as a duplicate of bug 86769 ***