[Development] Proposal: Deprecating platforms in Qt 5.6 that don't support lambda
Thiago Macieira
thiago.macieira at intel.com
Thu May 14 22:37:13 CEST 2015
On Thursday 14 May 2015 11:34:25 Matthew Woehlke wrote:
> On 2015-05-14 10:58, Thiago Macieira wrote:
> > On Thursday 14 May 2015 14:36:43 Olivier Goffart wrote:
> >> I'm afraid your solution is not working with temporaries containers.
> >
> > That should be submitted as a change request to the standard. There are a
> > couple of other cases where this bites people.
> >
> > It needs a new paper.
>
> Can you (both) please elaborate?
>
> That's... interesting. I'm taking a copy of the container and taking
> iterators from the copy. It seems to me that the RHS expression in a
> range-based for should most definitely not go out of scope within the
> for. Is that not the case? (Does range-based for just not work on
> temporaries at all?)
for (auto x : function(function2()))
If function returns a temporary and function passes through a reference, then
it effectively returns a dangling reference. That's because there's a
sequencing point shortly before the loop that causes all temporaries to be
destroyed.
See 6.5.4 [range.stmt] paragraph 1. It has an expansion of what the range for
is supposed to do. Note the presence of a semi-colon before the "for".
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Development
mailing list