On Tue, Sep 01, 2026 at 05:07:34PM -0400, Jason Merrill wrote:
> > where because of CWG2867 the first CLEANUP_POINT_EXPR wraps the whole
> > structured binding initialization.  The <anonymous> var is D.2759
> > above, we need to remember the return value from operator bool,
> > but it is then used in the if condition after the initialization.
> 
> Why do we call operator bool so soon?  The comment says
> 
> >           /* For structured bindings used in conditions we need to
> > evaluate                                                           the
> > conversion of decl (aka e in the standard) to bool or
> > integral/enumeral type (the latter for switch conditions)
> > before the get methods.  */
> 
> but doesn't say why.

http://eel.is/c++draft/dcl.struct.bind#7.sentence-10
requires that.
The paper had
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0963r3.html#Testing-is-sequenced-before-decomposing
about that, argues about the case of get performing moves out of the e
object and then the operator bool etc. accessing members after being moved
out.

>  I'd expect the conversion to happen after the whole
> initialization is complete: we do the whole structured binding declaration,
> and then once it's done we take e as the decision variable, which means
> converting it to bool at that point.  There's no need to introduce a bool
> temporary at all.

        Jakub

Reply via email to