https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112480
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Corey Kosak from comment #2)
> Thanks for the reply and the correction about illegally running the
> destructor.
>
> As for why the compiler can't do the optimization itself, I don't know, but
> the optimization isn't applied here either:
>
> ```
> void func(bool &b) {
> if (b) {
> b = false;
> }
> }
> ```
I think that is because that transformation would violate the memory model of
C++.